User loginNavigation |
Multiple overloads of the bind operatorHi! Let's say it makes a lot of sense in my domain to define the types WriteReference and ReadOnlyReference. I wish to create a monad that manipulates references, so my first idea was to define
return :: a -> ReadOnlyReference a It looks ugly but it does its job, even though I fear it won't play nice with Haskell syntactic sugar for monads. Does it make more sense to define Reference as a class, and then to define WriteReference and ReadOnlyReference as instances of this class, so that we can write something like:
class Reference r where get :: r a -> a instance Reference WR where get (WR x) = x instance Reference RR where get (RR x) = x bind :: (Reference r1, Reference r2) => r1 a -> (a -> r2 b) -> r2 b Can anyone help me understand why I should favor one approach over the other? Thanks By giuseppemag at 2010-03-08 11:28 | LtU Forum | previous forum topic | next forum topic | other blogs | 4824 reads
|
Browse archives
Active forum topics |
Recent comments
22 weeks 6 days ago
22 weeks 6 days ago
22 weeks 6 days ago
45 weeks 10 hours ago
49 weeks 2 days ago
50 weeks 6 days ago
50 weeks 6 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago