Not understanding Ocaml type signatures -


i have been working on trying understand this, , working harder on going hurt relationship ocaml, figured ask help.

i have simple function this site

let line_stream_of_channel channel = stream.from   (fun _ ->      try (input_line channel) end_of_file -> none);; 

okay cool, signature below it:

val line_stream_of_channel : in_channel -> string stream.t = <fun> 

in_channel argument , stream.t return value.

now why in ocaml can't do:

stream string 

and instead have

string stream.t 

looking @ the type signature of stream didn't me anywhere either. i've noticed same syntax weirdness stuff lists have unnatural

string list 

rather natural

list string 

but weird ".t" portion of stream type above.

can kinda explain going on here , why things done way? i've googled tutorials on explicit type signatures, types, etc in ocaml , in general lead here specific questions don't me.

thank you!

in ocaml's parameterized types, type constructor name comes after parameter name(s). that's way works. there languages (such haskell) use other order.

i ocaml order, have no problem it. have no problem other order.

the name t defined parameterized type in stream module. there's nothing trickier going on.

however, note return type of line_stream_of_channel string stream.t, not stream.t. stream.t isn't type. (it's function @ type level, or type constructor.)

$ ocaml         ocaml version 4.01.0  # 3;; - : int option = 3 # ^d  $ ghci ghci, version 7.4.2: http://www.haskell.org/ghc/  :? prelude> :t (3 :: integer) (3 :: integer) :: maybe integer 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -