Isn’t it beautiful?

(*
    bool isOdd(int n)
    {
        return ( (n%2) == 1);
    }
 
    int sqr(int n)
    {
        return n*n;
    }
 
    main(void)
    {
        for(int i = 1; i <= 10; i++)    // I know this is stupid!
            if(isOdd(i))
                printf("%d ", sqr(i));
    }
*)
 
#light

[1 .. 10]
    |> List.filter (fun n -> n % 2 = 1)
    |> List.map (fun n -> n*n)
    |> List.map (printfn "%d")
Advertisements
Posted in F#. Tags: . Leave a Comment »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: