Random programming things I'd want to remember

Tuesday, November 11, 2008

Learning a functional language

A challenge in learning a language is application of the newly-acquired knowledge. A wonderful web site, "Project Euler," presents a number of mathematical puzzles. I could learn F# by solving those problems. Here's the answer to problem number 1:


open System

let by32 = List.filter(fun n -> n%3 = 0 || n%5 = 0) [1 .. 9]

let rec sum list =
match list with
| h::tail -> (sum tail) + h
| []->0

printfn "%A" by32

let print x = printfn "%i" x
let x1 = sum by32

let main () = print x1



No comments: