haskell - How to add a (Vector v a) constraint to an instance declaration? -


given:

newtype matrix (w :: nat) (h :: nat) v     matrix :: v -> matrix w h v 

(where v data.vector.generic.vector v a, how this?)

and:

instance foldable (matrix w h v)     foldmap = foldmaptree  foldmaptree :: (vector v a, monoid m) => (a -> m) -> matrix w h v -> m 

ghc complains about:

matrix.hs:55:15:     not deduce (vector v a) arising use of ‘foldmaptree’     context (monoid m) 

changing to:

instance vector v => foldable (matrix w h v)     foldmap = foldmaptree 

gives:

matrix.hs:54:10:     variable ‘a’ occurs more in instance head       in constraint: vector v       (use undecidableinstances permit this) 

using undecidableinstances doesn't breaks else ... there simple solution problem ... other answers suggest undecidableinstances not "bad" per se. apparently can't work ...

as pointed out in comments, want not possible. foldable class expresses idea given type constructor, matrix w h v in case, can things any argument type a.

however foldmaptree works restricted range of types, namely there vector v a instance.

even if got instance vector v => foldable (matrix w h v) past type-checker, wouldn't because wouldn't express idea need vector v a hold possible a types, not particular one.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -