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

Ben Franksen ben.franksen at online.de
Thu Dec 6 11:40:59 EST 2007

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.


More information about the Haskell-Cafe mailing list