Jane Street OCaml Open Source

include struct
open Optional type'a is_the_default ='a Optional.is_the_defaultlet defaults_to = defaults_to let(!!)= override let singleton = singleton moduletype Singleton = Singleton end module Bool :sigtype t = bool module True_ : Singleton withtype real = t module False_ : Singleton withtype real = t end=structtype t = bool module True_ =(val singleton true: Optional.Singletonwithtype real = t)module False_ =(val singleton false: Optional.Singletonwithtype real = t)end includestructopen Bool.True_type true_ = t let true_ = t end includestructopen Bool.False_type false_ = t let false_ = t end module Test_bool :sigval f : ?x:true_ is_the_default -> ?y:false_ is_the_default -> unit -> bool * bool end=structlet f ?x ?y ()=let x = defaults_to x true_ inlet y = defaults_to y false_ in x, y ;; end let()=let f = Test_bool.fin assert ((true , false)= f ()); assert ((false, false)= f ~x:!!false()); assert ((false, true)= f ~x:!!false ~y:!!true()); ;; module Int :sigtype t = int module N_zero : Singleton withtype real = t module N_one : Singleton withtype real = t module N_million : Singleton withtype real = t end=structtype t = int module N_zero =(val singleton 0 : Optional.Singletonwithtype real = t)module N_one =(val singleton 1: Optional.Singletonwithtype real = t)module N_million =(val singleton 1_000_000 : Optional.Singletonwithtype real = t)end module Test_int :sigval f : ?x:Int.N_zero.t is_the_default -> ?y:Int.N_one.t is_the_default -> ?z:Int.N_million.t is_the_default -> unit -> int * int * int end=structlet f ?x ?y ?z ()=let x = defaults_to x Int.N_zero.tinlet y = defaults_to y Int.N_one.tinlet z = defaults_to z Int.N_million.tin x, y, z ;; end let()=let f = Test_int.fin assert ((0, 1, 1_000_000)= f ()); assert ((0, 1, 13)= f ~z:!!13()); assert ((1, 2, 3)= f ~x:!!1 ~y:!!2 ~z:!!3()); ;;



:(
Time to hit the books I guess...
 
For those of you familiar with C#/VB.NET and interested in learning about functional programming, take a look at F#. It's based on OCaml / ML so it provides a great stepping stone if you're coming from the Windows/.NET world.

If you visit the Jane Street site (linked in Andy's post), make sure to read their blog. If you're new to OCaml, it'll probably be a little over your head -- but they also frequently mention *how* they use functional programming / strict typing to their advantage, which'll help you learn how to structure your own code to get those same benefits.
 
For those of you familiar with C#/VB.NET and interested in learning about functional programming, take a look at F#. It's based on OCaml / ML so it provides a great stepping stone if you're coming from the Windows/.NET world.
Functional programming is "the bees knees" :), and F# is really, really great!!!
 
Back
Top Bottom