magistraleinformaticanetworking:spm:ocamlfs1
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
Entrambe le parti precedenti la revisioneRevisione precedente | |||
magistraleinformaticanetworking:spm:ocamlfs1 [23/03/2011 alle 16:25 (14 anni fa)] – Marco Danelutto | magistraleinformaticanetworking:spm:ocamlfs1 [23/03/2011 alle 16:31 (14 anni fa)] (versione attuale) – Marco Danelutto | ||
---|---|---|---|
Linea 93: | Linea 93: | ||
# main stream;; | # main stream;; | ||
- : int array list = [[|1; 4|]; [|9; 16|]] | - : int array list = [[|1; 4|]; [|9; 16|]] | ||
+ | # | ||
+ | </ | ||
+ | |||
+ | Even better, we can define our data type **stream** using the Ocaml type definition syntax: | ||
+ | < | ||
+ | # type 'a stream = Empty | Stream of ('a * 'a stream);; | ||
+ | type 'a stream = Empty | Stream of ('a * 'a stream) | ||
+ | # | ||
+ | </ | ||
+ | The farm functional semantics may therefore be defined by the function: | ||
+ | < | ||
+ | # | ||
+ | let rec farm f = function | ||
+ | Empty -> Empty | ||
+ | | Stream(x,y) -> Stream ((f x), (farm f y));; | ||
+ | val farm : ('a -> 'b) -> 'a stream -> 'b stream = <fun> | ||
+ | # | ||
+ | </ | ||
+ | Therefore the type of our //farm of map// will be correctly inferred as: | ||
+ | < | ||
+ | # farm (Array.map sq);; | ||
+ | - : int array stream -> int array stream = <fun> | ||
# | # | ||
</ | </ | ||
magistraleinformaticanetworking/spm/ocamlfs1.txt · Ultima modifica: 23/03/2011 alle 16:31 (14 anni fa) da Marco Danelutto