[Haskell-cafe] Re: Re: type class question

Peter Padawitz peter.padawitz at udo.edu
Fri Dec 7 07:34:42 EST 2007


Functional dependencies don't work in my case. Actually, I don't see why 
they should.

What seems to be needed here is a type class construct with a kind of 
record parameter so that instance conflicts cannot occur.

Jules Bean wrote:

> Ben Franksen wrote:
>
>> Ryan Ingram wrote:
>>
>>> On 12/5/07, Ben Franksen <ben.franksen at online.de> wrote:
>>> You would have to use functional dependencies or associated types to
>>> eliminate this error.  Alternatively, you can add a dummy argument 
>>> of type
>>> "block" and pass "undefined :: BlockType" in to help choose the 
>>> instance
>>> declaration.
>>
>>
>> Sounds reasonable, and in fact that was what I tried first. However
>>
>> data Command = Skip
>>
>> class Java block command | command -> block where
>>   block_ :: [command] -> block
>>
>>   compBlock :: [Command] -> block
>>   compBlock = block_ . map compCommand
>>
>>   compCommand :: Command -> command
>>
>> still gives
>>
>>     Could not deduce (Java block command1)
>>       from the context (Java block command)
>>       arising from use of `block_' at Bla.hs:7:14-19
>>     Possible fix:
>>       add (Java block command1)
>>       to the class or instance method `compBlock'
>>     In the first argument of `(.)', namely `block_'
>>     In the expression: block_ . (map compCommand)
>>     In the definition of `compBlock':
>>         compBlock = block_ . (map compCommand)
>>
>> which is /exactly/ the same error as I get w/o the fundep.
>
>
> Yes, because command determines block but block doesn't determine 
> command.
>
> So in a usage of 'compBlock' it has no way of deciding which 'command' 
> to use, although it can choose the block from the return type.
>
> You could have command -> block, block -> command, if that is indeed 
> true.
>
> Jule
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


-- 
Prof. Dr. Peter Padawitz
Informatik 1            
University of Dortmund  
D-44221 Dortmund
Germany 
phone           +49-231-755-5108
fax             +49-231-755-6555
secretary       +49-231-755-6223
email           peter.padawitz at udo.edu
internet        http://funlog.padawitz.de



More information about the Haskell-Cafe mailing list