Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Exercise 3.2 – Some List functions
- // a. Define a function pmLength ls that computes the length of a list. Use pattern matching.
- // For example, pmLength [‘x’; ‘y’; ‘z’ ] should return 3.
- // b. Define a function pclSum ls that sums all the numbers in a list. For example, pclSum [2; 3; 5; 8 ] should return 18.
- open System
- let pclSum (ls) : int=
- List.reduce(+) ls
- printfn "%i" (pclSum([1;2;3;4;5]))
- Console.ReadKey() |> ignore
- // Exercise 3.3 – Lists
- // Define a function, takeSome n ls that returns list of first n elements from the list ls.
- // Define the function using pattern matching:
- // Example takeSome 2 ['a';'b'; 'c'; 'd'] should return ['a'; 'b'].
- // Exercise 4.1 – List functions
- // a. Define the function pclFold . Use pattern matching. You are not allowed to use the standard F# functions.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement