Re: [Haskell-cafe] How to do this with associated types?

2010-07-26 Thread Ryan Ingram
On Sun, Jul 25, 2010 at 1:53 PM, Alexey Karakulov ankaraku...@gmail.com wrote: Suppose I have one piece of code like this: class Result r e | r - e where    failure :: e - r a     success :: a - r a Maybe instance is discarding failure information: instance Result Maybe e where    

[Haskell-cafe] How to do this with associated types?

2010-07-25 Thread Alexey Karakulov
Suppose I have one piece of code like this: class Result r e | r - e where   failure :: e - r a     success :: a - r a at :: Result r String = [a] - Int - r a at xs i = if i = 0 i length xs     then success (xs !! i)     else failure Wrong index Either instance of

Re: [Haskell-cafe] How to do this with associated types?

2010-07-25 Thread Christopher Lane Hinson
But what to do with Maybe? instance Result Maybe where type Failure Maybe = forall e. e -- can't do this failure _ = Nothing success x = Just x Normally, I would use: type Failure Maybe = () Unless the ability to discard information of any type is somehow a salient feature.