Problem #1
February 28, 2008 – 5:03 amSo I begin this long journey by tackling the first problem. It doesn’t seem hard you just need to return the tail of list. It seems like you can just use List.tl? The problem is you can’t. List.tl returns ‘a list but you need ‘a . So another way is to get the size of the list and return the tail by specifying which index to return. “|> ” change functions together so that you pass the result from one function as a parameter to another.
#light
let thisList = [1; 2; 3; 4; 5; 6]
let l = List.length thisList
List.nth thisList (l - 1)
|> printf "Answer: %d"
Very straight forward.
2 Responses to “Problem #1”
I don’t know how you compose functions in F#, but in Haskell: last = head.reverse
By Greg M on Feb 28, 2008
I did something like you had mentioned for my solution Greg …
#light
let myList =
[1; 2; 3; 4]
|> List.rev
|> List.hd
|> printf “Answer: %d”
The full solution and some other of the 99 problems are available at frickinsweet.com/99problems
By Ryan Lanciaux on Feb 28, 2008