0

I'm reading the book "The Haskell Road to Logic, Math and Programming" and I download their code from the second chapter(http://homepages.cwi.nl/~jve/HR/), but when I try to compile the code, it doesn't work.

The error message is:

TAMO.hs:85 - Syntax error in instance head (variable expected)

What variable is expected? I've never used Haskell before and have no idea what the compiler(Hugs) want me to do to fix it.

class TF p where 
  valid :: p -> Bool
  lequiv :: p -> p -> Bool
instance TF Bool
  where
  valid  = id
  lequiv f g = f == g

instance TF p => TF (Bool -> p)
  where
  valid f = valid (f True) && valid (f False)
  lequiv f g = (f True) `lequiv` (g True)
           && (f False) `lequiv` (g False)
Cactus
  • 27,075
  • 9
  • 69
  • 149
jvrn3
  • 600
  • 1
  • 5
  • 18

1 Answers1

3

It compiled for me, but I had to fix the indentation (lequiv needed to be at the same level as valid), and add the FlexibleInstances language extension using

{-# LANGUAGE FlexibleInstances #-}

(I am using GHC, I am not sure what the equivalent for HUGS is)


Additional info:

The last answer in Instance Show for function shows you how to use FlexibleInstances in Hugs.

Community
  • 1
  • 1
jamshidh
  • 12,002
  • 17
  • 31