[Haskell-cafe] Class and Instance
Patrick Browne
patrick.browne at dit.ie
Sat Jun 11 11:49:16 CEST 2011
Thanks for the feedback. I have two further questions
1. Why is it that the Containers class signature does not allow
instances to be list of list? I suspect it is because x is a constructor.
2. How would I change the Containers class signature to allow instances
to be lists of lists.
Thanks,
Pat
-- x is a type constructor, not a type
class Containers x y where
insert :: y -> x y -> x y
remove :: y -> x y -> x y
whatsIn :: x y -> [y]
instance Containers [] Char where
insert y [] = y:[]
insert y m = y:m
remove _ [] = []
remove x (y:ys) | x == y = remove x ys
| otherwise = y : remove x ys
whatsIn = id
instance Containers [] Integer where
insert y [] = y:[]
insert y m = y:m
remove _ [] = []
remove x (y:ys) | x == y = remove x ys
| otherwise = y : remove x ys
whatsIn = id
-- cannot have containers of containers.
-- instance Containers [] [] where
-- container.hs:41:23:
-- `[]' is not applied to enough type arguments
-- Expected kind `*', but `[]' has kind `* -> *'
-- In the instance declaration for `Containers [] []'
-- Failed, modules loaded: none.
This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie
More information about the Haskell-Cafe
mailing list