Something is wrong with this forum - you can't delete and it don't show your entire posts

By on 6/24/2009 9:27 PM ()

The Problem is, that (::) = 'a -> 'a list ->'a
and List.fold is expection a function that takes 'state 'item -> 'state, so (::) has it just reversed.
The following code has it right but the reversed result:

1
2
let (!!) l a = a :: l
let r = List.fold (!!) [] [1..4]

For an alternativ try using List.foldBack

By on 6/24/2009 9:26 PM ()
1
2
3
4
let (!!) a l = a :: l

let r = List.foldBack (!!) [] [1..4]

Is working the way we excpect - and no you can't use (::) - it really seems to be special.

By on 6/24/2009 9:31 PM ()

To use :: as a function, use List.Cons. But, the signature is 'a * 'a list -> 'a list, so this wouldn't work with foldBack anyways.

Just guessing cause I don't know, but the cons operator might be special because operators can't start with colon:

1
2
3
4
5
 regexp first-op-char = !$%&*+-./<=>?@^|~ 
regexp op-char       = first-op-char | : 
 
token symbolic-op  =  
    | first-op-char op-char*
By on 6/24/2009 10:29 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