Hello.

As Robert says you've seen binding function to yet one name.

Moreover, you allowed to bind function with a fewer arguments then need by function definition to identifier. I.e. it' looks like you simply lock values of some arguments.
F.ex.:

1
2
3
4
 > let sum2 = (+2);;
 val sum2 : (int -> int)
 >sum2 3;;
 val it : int = 5

Such technique is known as curryng or partial application and it plays major role when you write programms in functional style (i.e. like formulas, when result of computation only depends from arguments and not from state of rest world).
If you see signatures of functions in fsi, they

also showes in such way:

1
2
 > List.map;;
 val it : (('a -> 'b) -> 'a list -> 'b list) =<fun:clo@0>

('a -> 'b) -- the first argument of List.map (function map in module List) is function whom takes one argument of type 'a and produces value of type 'b where 'b is any supported type
-> 'a list -- second argument of List.map is list of values which type is 'a
-> 'b list -- List.map produces value of type "list of values with type 'b"

For now if we type

1
2
3
4
5
 > List.map sum2;;

val it : (int list -> int list) = 
<fun:it@9>

For now we can see:
int list -- first argument of partially applied function List.map has type int list (int is substituted when F# had parsed definition of sum2, so it knows what concrete type of 'a is)
-> int --partially applied List.pam produces value of type "list of values with type int"

</fun:it@9></fun:clo@0>

By on 11/26/2007 11:17 PM ()

The clue here is that length is in lower class, the .NET property on the string class in frat starts with an upper case (F# is case sensative).

1
2
3
#light
let s1 = String.length
printf "%A" s1

Gives:

1
2
3
val s1 : (string -> int)

<fun:clo@4>

So what you are doing is binding a function (which remember is just a value) from the OCaml compatality String module to the identifier s1, s1 can now also be used to find the length of a string:

1
printf "%i" (s1 "Test")
By on 11/25/2007 9:17 AM ()
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