use this instead:

List.iter (fun x -> x |> ignore) x_list;;

ignore is a function that takes anything and return the unit type.

ignore : 'a -> unit

Of course the above expression does nothing.

List.iter is really only used to perform side-effect code otherwise you should use map to convert values in the List from one to another or fold to aggregrate the elements of the List into a single value.

As LLB pointed out unit is a type used like void in other languages that has only one value '()'.

By on 5/21/2009 2:18 PM ()

Oh by the way the '|>' operator is called pipe and allows you to chain results from lefthand expression into the last argument of the function defined by the righthand expression.

So for example if you have the following functions:

let foo a b = a + b

let bar a b = a * b

let printAnInt a = printf "%d" a

1 |> foo 2 |> bar 3 |> printAnInt

this is equivalent to:

printAnInt(bar 3 (foo 2 1))

you will see this idiom used alot.

By on 5/21/2009 2:25 PM ()

Hi,

The List.iter function expects a function returning the unit type (that's nearly the same as the "void" type of other languages).

Look here: [link:research.microsoft.com]

You might want to use List.map instead.

Laurent

By on 5/21/2009 1: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