{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
class Fractional f => Point3D p f | p -> f where
x :: p -> f
y :: p -> f
z :: p -> f
class (Fractional fr, Point3D p fr, Foldable f) => HasPoints3D ps p f where
points :: ps -> f p
I made Point3D class to cover diverse implementations of 3D Point. And I made HasPoints3D class to cover all things that have some points. The second type variable f in Point3D definition is determined by the first type variable p. So, I think this definition of HasPoints3D have no problem, because fr is can determined by p.
I know that it may cause typechecker loop. So, I added {-# LANGUAGE UndecidableInstances #-}. But it is not working, it says Not in scope: type variable ‘fr’. Is there another haskell extension to make this work? Or haskell just can't deal with this situation?