[Haskell-cafe] nice simple problem for someone struggling....

Nicholls, Mark Nicholls.Mark at mtvne.com
Fri Dec 21 09:36:05 EST 2007

I'm just trying to pick up the basics....and I've managed to write this
code...which remarkably works......




module Main where


data SquareType = SquareConstructor Int


class ShapeInterface shape where

      area :: shape->Int


data ShapeType = forall a. ShapeInterface a => ShapeType a


instance ShapeInterface SquareType where

      area (SquareConstructor sideLength) = sideLength * sideLength


main = do 

      putStrLn (show (area (SquareConstructor 4)))

      name <- getLine

      putStrLn ""




But my next iteration was to try to parametise SquareType....


So something like 


data SquareType a = Num a => SquareConstructor a


but of course doing this breaks everything.......sepecifically the
instance declaration


`SquareType' is not applied to enough type arguments

Expected kind `*', but `SquareType' has kind `* -> *'

In the instance declaration for `ShapeInterface SquareType'


And I can't seem to get it to work.....

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071221/c7893580/attachment.htm

More information about the Haskell-Cafe mailing list