File: fonctions2.ml

package info (click to toggle)
ocamlwc 0.3-21
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 172 kB
  • sloc: makefile: 83; ml: 55; sh: 3
file content (15 lines) | stat: -rw-r--r-- 407 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(* fonctions dans un record *)
type 'a foo = {n:int; f: 'a -> 'a} ;;
let foo = {n=42; f=fun x -> x} ;;
foo.f 33;;

(* fonctions dans une paire.  *)
let fp = ( (fun x -> x+1), (fun x -> x*x) );;

(* attention aux parantheses *)
let fp = ( fun x -> x+1, fun x -> x*x );;

(* extraction des fonctions d'une paire *)
(fst fp) 42;;
(fst fp) ((snd fp) 10);;
(fst fp) (snd fp) 10;; (* attention aux parantheses *)