Advanced Functional Prog.
back - up - next
Lists' processing
- Type generalization/parameter
type 't Stack = NewStack | Push of 't*('t Stack);;
let s1 : int Stack = Push (3,Push(2,Push(1,NewStack)));;
let s2 : string Stack = Push ("uha.fr",Push("google.fr",NewStack));;
- Function generalization (higher-order)
let rec reduceStack v f s =
match s with
| NewStack -> v
| Push (v',s') -> f v' (reduceStack v f s');;
reduceStack NewStack (fun x y->Push(x,y)) s2;; // id
reduceStack s2 (fun x y->Push(x,y)) s2;; // append
reduceStack NewStack (fun x y->Push(String.length x,y)) s2;; // map
...
reduceStack [] (fun x y->x::y) s2;; // isomorphism
Nb. F#
can use all the .net
API with in particular C#
libraries (see String.length
method above).
8
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp