[Haskell-cafe] Re: Re: type class question
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
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
>> 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
> 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
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
Prof. Dr. Peter Padawitz
University of Dortmund
email peter.padawitz at udo.edu
More information about the Haskell-Cafe