Would be nice to have

By on 4/16/2009 2:36 PM ()

+1 for a where clause.

regards,

Danny

By on 4/15/2009 7:33 AM ()

Vote: Yes!

I use it a lot in Haskell and would in F# too, if it were to become available.

By on 4/15/2009 1:17 PM ()

Vote: yes!

Solves a big readability issue: one does not need to read the code backwards!

By on 4/13/2009 10:18 AM ()

Vote: yes!

Solves a big readability issue: one does not need to read the code backwards!

This:

1
2
3
4
5
let fibo n = fst fibo_aux n
  where rec fibo_aux = function
    | 0 -> (1, 1)
    | 1 -> (1, 2)
    | n -> (a, a + b) where let (a, b) = fibo_aux ( n - 1 )

Vs:

1
2
3
4
5
6
7
let fibo n = fst fibo_aux n
  let rec fibo_aux =
    | 0 -> (1, 1)
    | 1 -> (1, 2)
    | n -> let a, b = fibo_aux ( n - 1 )
             (a, a + b)
    fibo_aux n

seems no more or less readable. What am I missing?

By on 4/13/2009 10:34 AM ()

Vote

Sincerely,

Saagar

By on 2/18/2010 3:58 PM ()

Vote: yes!

Solves a big readability issue: one does not need to read the code backwards!

This:

1
2
3
4
5
let fibo n = fst fibo_aux n
  where rec fibo_aux = function
    | 0 -> (1, 1)
    | 1 -> (1, 2)
    | n -> (a, a + b) where let (a, b) = fibo_aux ( n - 1 )

Vs:

1
2
3
4
5
6
7
let fibo n = fst fibo_aux n
  let rec fibo_aux =
    | 0 -> (1, 1)
    | 1 -> (1, 2)
    | n -> let a, b = fibo_aux ( n - 1 )
             (a, a + b)
    fibo_aux n

seems no more or less readable. What am I missing?

When you have many local functions some of which could be mutually recursive or you have many intermediate results, just look at the count less examples in Haskell. It makes the code even more elegant and more readable.

(Here is some code that compiles and works.)

1
2
3
4
5
6
7
8
9
10
 
let rec fibo n = fst (fibo_aux n)
and fibo_aux = function
    | 0 -> (1, 1)
    | 1 -> (1, 2)
    | n -> let a, b = fibo_aux ( n - 1 )
           (b, a + b)

for i in 0..5 do
    printfn "%A" (fibo i)

Does that work with multiple definitions and ones which are mutually recursive?

By on 4/13/2009 11:00 AM ()

(Here is some code that compiles and works.)

1
2
3
4
5
6
7
8
9
10
11
 
let rec fibo n = fst (fibo_aux n)

and fibo_aux = function
    | 0 -> (1, 1)
    | 1 -> (1, 2)
    | n -> let a, b = fibo_aux ( n - 1 )
           (b, a + b)

for i in 0..5 do
    printfn "%A" (fibo i)
By on 4/13/2009 10:44 AM ()

(Here is some code that compiles and works.)

1
2
3
4
5
6
 

let rec fibo n = fst (fibo_aux n)

and fibo_aux = function

The problem here is that both fibo and fibo_aux are exposed in the same scope. Using "where" would allow hiding of fibo_aux (and any additional inner function declarations).

By on 4/13/2009 11:12 AM ()

The problem here is that both fibo and fibo_aux are exposed in the same scope. Using "where" would allow hiding of fibo_aux (and any additional inner function declarations).

I see. You can always wrap all this under "let fibo n = <all that> fibo n" to get the scoping, but that does defeat some of the syntactic elegance.

By on 4/13/2009 11:19 AM ()

Using the `and` keyword is not like a where clause in haskell, it does not seem to work with multiple definitions.

By on 4/13/2009 11:02 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