class - Haskell type enforcement on typeclass parameters -


i trying follow along machine learning book , knowing bit future content trying make code generalisable.

here code. have other instances of dataset, have now.

data superviseddataset x y = superviseddataset [([x], y)] deriving (show)         class dataset                                                             augment :: x -> -> --augment each input vector, making x head.                                                         instance dataset (superviseddataset x y)                                      augment v (superviseddataset ds) =·                                                let xsys = unzip ds in                                                             superviseddataset $ zip (map (v:) $ fst xsys) (snd xsys)   

i trying enforce type of first parameter of superviseddataset first parameter of augment requested type checker in ghc.

perceptron.hs:16:7:   couldn't match type `x1' `x'     `x1' rigid type variable bound          type signature            agument :: x1 -> superviseddataset x y -> superviseddataset x y          @ perceptron.hs:14:3     `x' rigid type variable bound         instance declaration @ perceptron.hs:13:37   expected type: superviseddataset x1 y     actual type: superviseddataset x y   in expression:     superviseddataset $ zip (map (v :) $ fst xsys) (snd xsys)   in expression:     let xsys = unzip ds     in superviseddataset $ zip (map (v :) $ fst xsys) (snd xsys) 

i understand why receiving error, don't know how fix it. ideas appreciated. thanks

thanks time.

class dataset   augment :: x -> -> 

could written as

class dataset   augment :: forall x . x -> -> 

try instead

data superviseddataset x y = superviseddataset [([x], y)] deriving (show)   class dataset f   augment :: -> f b -> f b  instance dataset superviseddataset   augment v (superviseddataset ds) =     let xsys = unzip ds in       superviseddataset $ zip (map (v:) $ fst xsys) (snd xsys) 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -