Problem #5

Again this is not too difficult -- After a little while, however, we'll be back into the more challenging stuff.

"Reverse a list."

    1 #light

    2 

    3 let listerine = [1 .. 40] |> List.rev |> List.iter (printfn "%d")

 Basically everything looks familiar until we get to the List.iter statement. In case it's not obvious, the iter statement traverses thru each element of the list -- so really all we're doing is reversing the list we've created and printing each element. 

kick it on DotNetKicks.com  


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: , ,
Categories: F#

4 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Related posts

Comments

March 8. 2008 14:37

Jesus DeLaTorre

1. let rec reverse_list l =
2. match l with
3. | [] -> []
4. | (x::xs) -> (reverse_list xs) @ [x];;
5. myList |> reverse_list |> List.iter (printf "[%d]") ;;

This was my solution. It was kinda inspired by your use of |>

Jesus DeLaTorre

March 8. 2008 15:12

ryan

I love the |> operator Smile

ryan