2 Replies - 3315 Views - Last Post: 17 March 2010 - 05:11 PM

#1 s243a   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 137
  • Joined: 17-March 10

Haskell 'Logic' is not applied to enough type arguments

Posted 17 March 2010 - 03:26 PM

I'm trying to understand the type system in haskell so I wrote the following:

data Logic a b = Or a b 
               | And a b
               | Xor a b
               | NOr a b
               | NAnd a b
instance Show Logic where
     show (And a B)/>="(" ++ show(a) ++ "And" ++ show(B)/> ++")"
     show (Or a B)/> = "(" ++ show(a) ++ "or" ++ show(B)/> ++")"
     show (Xor a B)/> = "(" ++ show(a) ++ "Xor" ++ show(B)/> ++")"
     show (NOr a B)/> = "(" ++ show(a) ++ "NOr" ++ show(B)/> ++")"
     show (NOr a B)/> = "(" ++ show(a) ++ "NAnd" ++ show(B)/> ++")"


I get the following error:

'Logic' is not applied to enough type arguments
Expected kind '*', but 'Logic' has kind * - > * - > *'
In the instance delaration for 'Show Logic'

Any help would be appreciated.

This post has been edited by s243a: 17 March 2010 - 03:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Haskell 'Logic' is not applied to enough type arguments

#2 s243a   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 137
  • Joined: 17-March 10

Re: Haskell 'Logic' is not applied to enough type arguments

Posted 17 March 2010 - 04:58 PM

As a side note, I'm able to do this:

showLogic (And a B)/> ="(" ++ show(a) ++ "And" ++ show(B)/> ++")"
showLogic (Or a B)/> = "(" ++ show(a) ++ "or" ++ show(B)/> ++")"
showLogic (Xor a B)/> = "(" ++ show(a) ++ "Xor" ++ show(B)/> ++")"
showLogic (NOr a B)/> = "(" ++ show(a) ++ "NOr" ++ show(B)/> ++")"
showLogic (NOr a B)/> = "(" ++ show(a) ++ "NAnd" ++ show(B)/> ++")"


But this is not what I'm trying to do.
Was This Post Helpful? 0
  • +
  • -

#3 s243a   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 137
  • Joined: 17-March 10

Re: Haskell 'Logic' is not applied to enough type arguments

Posted 17 March 2010 - 05:11 PM

View Posts243a, on 17 March 2010 - 03:58 PM, said:

As a side note, I'm able to do this:

showLogic (And a B)/> ="(" ++ show(a) ++ "And" ++ show(B)/> ++")"
showLogic (Or a B)/> = "(" ++ show(a) ++ "or" ++ show(B)/> ++")"
showLogic (Xor a B)/> = "(" ++ show(a) ++ "Xor" ++ show(B)/> ++")"
showLogic (NOr a B)/> = "(" ++ show(a) ++ "NOr" ++ show(B)/> ++")"
showLogic (NOr a B)/> = "(" ++ show(a) ++ "NAnd" ++ show(B)/> ++")"


But this is not what I'm trying to do.


I finally figured it out. It was necessary to put in constraints and make sure that my type expressions had a capital S for show:

instance (Show(a),Show(B)/>)=>Show (Logic a B)/> where
     show (And a B)/>="(" ++ (show a) ++ "And" ++ (show B)/> ++")"
     show (Or a B)/> = "(" ++ show(a) ++ "Or" ++ show(B)/> ++")"
     show (Xor a B)/> = "(" ++ show(a) ++ "Xor" ++ show(B)/> ++")"
     show (NOr a B)/> = "(" ++ show(a) ++ "NOr" ++ show(B)/> ++")"
     show (NAnd a B)/> = "(" ++ show(a) ++ "NAnd" ++ show(B)/> ++")"

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1