The keyword reference

[link:msdn.microsoft.com]

links a decent description; briefly

function patterns

is shorthand for

fun arg -> match arg with patterns

By on 4/29/2011 11:05 AM ()

I still don't understand the "function (x : float) :: y :: t -> f y x :: t "

What are the match patterns?

By on 4/29/2011 11:10 AM ()

Another small detail that is important to understand the syntax: The first "|" of a function or match construct is optional.

Also: patterns are allowed in the argument list of regular functions, too. So you could use "fun" instead of "function" here. The only difference is that you need one more set of parentheses.

By on 4/29/2011 2:04 PM ()

I still don't understand the "function (x : float) :: y :: t -> f y x :: t " What are the match patterns?

(x : float) :: y :: t

is a pattern, it matches a list of at least two elements where the list elements have type float. It's a composite pattern of two 'cons' patterns and a type annotation pattern, see

[link:msdn.microsoft.com]

So for example

1
2
3
let l = [1.1; 2.2; 3.3]
match l with
| (x : float) :: y :: t -> ...

will match and bind 'x' to '1.1', 'y' to '2.2', and 't' to the list '[3.3]'.

By on 4/29/2011 12:53 PM ()

It accepts a list of float as an argument (it is forced to be float by ': float' thing), and decouples it to the head (x), the head of tail (y) and the rest. In case list contains 0 or 1 elements, it throws an exception.

By on 4/29/2011 12:11 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper