Problem #4

We've already done this in Problem #2 but for the sake of answering all the problems we'll do it again :) 

"Find the number of elements of a list."

Using the built in list functions and the pipeline operator we come up with the answer pretty easily. 

    1 #light

    2 

    3 let listerine = [1 .. 40]  |> List.length |> printfn "List length: %d"

 

There are not really any new concepts in this solution -- on to problem 5! As always, please feel free to post your solution if it is any different / more elegant -- we're using this excerise a way to better learn the language. 

kick it on DotNetKicks.com  


Be the first to rate this post

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

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

Related posts

Comments

March 8. 2008 01:24

Jesus DeLaTorre

Hey ryan, I'm slowly catching up to you.

This is the solution I came up for solution #4.

let rec nr_elements l =
match l with
| [] -> 0
| x::xs -> 1 + nr_elements xs;;

I'm jdelator on DNK btw. Smile

Jesus DeLaTorre

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

August 28. 2008 14:22