[Haskell-cafe] nice simple problem for someone struggling....
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
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
`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...
More information about the Haskell-Cafe