Journal

Sign in to follow this  
  • entries
    122
  • comments
    246
  • views
    89738

Haskell

Sign in to follow this  
Daerax

247 views

I have been trying to write programs in OCaml, with the keyword here being trying. What little I managed to learn has faded quite quickly due to my disuse of the knowledge. So far I have been programming by "instinct":
randoms snips:
let addm a b m = (a + b) mod m
let mm a b m = (a * b) mod m

let eq a b m = let g = a - b in if (g mod m) == 0 then true else false;;

let f n = let rec g a b n l = if n + 1 == List.length l then l else g (a + b) a n ( a ::l) in g 0 1 n []

let rec general_sorder_reccurence b a p q n l = if n + 1 == List.length l then l else general_sorder_reccurence (p*a + q*b) a p q n (a::l)

let sqf n = List.map (fun x -> x * x) (f n)
let sumf n = List.fold_left (+) 0 (sqf n)

let fgen_l n = let rec gen_l n l = if List.length l == n then l else gen_l n ((sumf (List.length l)) :: l) in gen_l n []

Coding by ear is no fun so I decided I need to read a book on functional programming as I do not really have time to learn by experimentation. So I picked up a book on Functional programming taught with Haskell.

So far I must say I quite like this language and do not find it esoteric at all (perhaps it is because I never got too steeped in imperative programming or because I meet with the cousins of many of the notions of the language daily). Although I feel the Ocaml syntax (especially its pattern matching stuff) can be quite elegant, Haskell is alot more natural.

List comprehension and lazy evaluation are also really useful tools. (Nemerle has both of these too). I have only just begun and shall be reporting in with more substantial learnings as time passes.
Sign in to follow this  


1 Comment


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now