I am working on a homework and need some help The task: In the first step I need to define a new type class for a overloaded function "genDrop". It should behave like "drop" (for Int), but not limited to Int. In a second step it should be instantiated for types Int, Nat, PosNat and Int'.
So here my code:
class GenDrop a where
genDrop :: a -> [a] -> [a]
instance GenDrop Int where
genDrop 0 s = s
genDrop n (_:s) | n>0 = genDrop (n-1) s
genDrop _ [] = []
instance GenDrop Nat where
genDrop Zero s = s
genDrop (Succ n) (_:s) = genDrop n s
genDrop _ [] = []
instance GenDrop PosNat where
genDrop One (_:s)= s
genDrop (Succ' n) (_:s) = genDrop n s
genDrop _ [] = []
instance GenDrop Int' where
genDrop Zero' s = s
genDrop (Plus n) (_:s) = genDrop n s
genDrop (Minus n) s = s
genDrop _ [] = []
But on compiling i get an error:
parse error on input 'instance'
instance GenDrop Int where
I can't figure out whats wrong.
instancedefinitions outside theclassdeclaration.instancestarts on the same column as the wordclass, i.e. at the very beginning of the line.