<int>Is there any other way to achieve a similar result?

Add generic parameter to your type
</int>

1
2
3
4
5
6
7
8
 

type MyType< 'Container > = 
    {
        Items : 'Container
       ...    } 

By on 3/10/2011 8:34 AM ()

but now it's not a enumeration/collection anymore ;)

As a sidenote:

this is why I really want real typeclasses for F#! - Of course you can handle this situation just by sticking to seq/IEnumerable but just imagine the beauty of a collection-type class with map/fold/filter/... and even better imagine you could define all those functions in terms of fold(r) like you can in Haskell ;)

By on 3/10/2011 9:04 AM ()

Hi,

what about using an algebraic type:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 

type 'a MyItemType = 
    | MyItemTypeSeq of 'a seq
    | MyItemTypeArr of 'a array
    | MyItemTypeList of 'a list
    with
    member me.Length = 
        match v with
        | MyItemTypeSeq s -> Seq.length s
        | MyItemTypeArr a -> Array.length a
        | MyItemTypeList l -> List.length l
 
    static member map f v = 
        match v with
        | MyItemTypeSeq s -> MyItemTypeSeq (Seq.map f s)
        | MyItemTypeArr a -> MyItemTypeArr (Array.map f a)
        | MyItemTypeList l -> MyItemTypeList (List.map f l)

You can easily implement all the stuff you need (see the map example) and use it just like Seq or List or whatever

If not I guess you can use the fact that every array, list, ... is a Seq to - so you just define your Items as 'a seq

By on 3/10/2011 4:28 AM ()

Hi,

Thanks a lot !

This is very close to what I was looking for.

By on 3/10/2011 7:57 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