just my 50ct:

if you use Seq.iter or some other Seq method the resulting object will be a sequence itself - and those are lazy evaluated.

So your construction function will only be called IF you extract elements from this sequenz.

By on 12/2/2008 10:11 PM ()

just my 50ct:

if you use Seq.iter or some other Seq method the resulting object will be a sequence itself - and those are lazy evaluated.

So your construction function will only be called IF you extract elements from this sequenz.

This is true of Seq.map, but not Seq.iter; Seq.iter evaluates it all now and returns nothing.

By on 12/2/2008 11:41 PM ()

I cannot reproduce the behavior you're describing here; can you share a code snippet?

See below

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#light

type Foo() =
    member x.SomeMethod n =
        printfn "%d" n
        n

let mylist = [ new Foo(); new Foo() ]

printfn "way #1"
// can use 'do'...
mylist |> Seq.iter (fun x -> do x.SomeMethod 42)
printfn "way #2"
// but piping to 'ignore' is preferred
mylist |> Seq.iter (fun x -> x.SomeMethod 42 |> ignore)
By on 12/2/2008 4:43 AM ()

I'm extremely afraid I can't post a snippet because that behavior was only observed while developing an F# implementation of an algorithm I'm not allowed to disclose. What I can say is this: in some case using do works, but in the case I've reported of the function doesn't get called at all (verified through debugging).

If I wrap the function this way

1
2
3
let a b c =
     b.OneFunc c
     Console.WriteLine("ok")

it works.

However the code structure involved with the issue is the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
type A(b:string) =
    [<DefaultValue>]
    val mutable public _someField : int

    member x.B (c:sometype) = ...(implementation)
    abstract C : sometype seq -> decimal

type B(b:string) =
    inherit A(b)

    sometype

    override x.C s =
        _someField <- ... (part of the algorithm)
        x.B s

That's simplified, but it'll hopefully be enough for you to get a clue of what's causing the issue.

Thanks about suggesting piping to ignore, that was a totally unknown technique to me :)

Regards

By on 12/2/2008 7:33 PM ()

Hm. What version of F# do you have installed? (1.9.6.2 is the latest release.)

Does the problem still happen if you do something along the lines of

1
mycollection |> List.of_seq |> Seq.iter ...

(transform to list before calling iter)?

By on 12/2/2008 9:15 PM ()

Actually I was already using Set.iter since the collection is a set, but I've tried making a List out of it as you suggested and the problem still occurs.

I'm using v1.9.6.2 (Sept. CTP). Also, please let me remark that piping to ignore works while using do causes the described behavior.

Regards

By on 12/3/2008 4:20 AM ()

Hm. What version of F# do you have installed? (1.9.6.2 is the latest release.)

Does the problem still happen if you do something along the lines of

1
mycollection |> List.of_seq |> Seq.iter ...

(transform to list before calling iter)?

That is the point I am trying to make: if you transform it to a list the sequenz will be evaluated completly to construct the list.

Try it with infinite sequenzes - to_list will not work but Seq.map etc. will!

By on 12/2/2008 10:13 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