ugliness with state parameter in ST stuff

Tom Pledger Tom.Pledger@peace.com
Wed, 7 Aug 2002 09:28:24 +1200


Hal Daume III writes:
 | > Try this instead:
 | > 
 | > > instance Foo (Bar RealWorld) where
 | > >      foo = stToIO . getFirst
 | > 
 | > It should work OK, since it doesn't have the free type variable.
 | 
 | Yes, this is what I have.  But this kind of makes the fact that I'm
 | in ST useless, since afaik (ST RealWorld) is basically the same as
 | IO, so there's no reason for me to stay in the ST realm...

How about making Foo a class of constructors of kind *->* instead of *?

    import ST

    data Bar s = Bar (STArray s Int Int)
    getFirst (Bar arr) = readSTArray arr 0

    class    Foo a   where foo :: a s -> IO Int
    instance Foo Bar where foo = stToIO . getFirst