I feel like I am doing something wrong, as I am not even managing to reproduce Haskell's lens tutorial:
> import Control.Lens
> data Point = Point { _x :: Double, _y :: Double } deriving (Show)
> data Atom = Atom { _element :: String, _point :: Point } deriving (Show)
> point = lens _point (\atom newPoint -> atom { _point = newPoint })
> :t point
point :: Functor f => (Point -> f Point) -> Atom -> f Atom
> point :: Lens' Atom Point = lens _point (\atom newPoint -> atom { _point = newPoint })
<interactive>:6:10: error:
• Illegal polymorphic type: Lens' Atom Point
Perhaps you intended to use RankNTypes or Rank2Types
• In a pattern type signature: Lens' Atom Point
In the pattern: point :: Lens' Atom Point
In a pattern binding:
point :: Lens' Atom Point
= lens _point (\ atom newPoint -> atom {_point = newPoint})
> :set -XRankNTypes
> point :: Lens' Atom Point = lens _point (\atom newPoint -> atom { _point = newPoint })
<interactive>:8:29: error:
• Couldn't match type ‘(Point -> f0 Point) -> Atom -> f0 Atom’
with ‘forall (f :: * -> *).
Functor f =>
(Point -> f Point) -> Atom -> f Atom’
Expected type: Lens' Atom Point
Actual type: (Point -> f0 Point) -> Atom -> f0 Atom
• In the expression:
lens _point (\ atom newPoint -> atom {_point = newPoint})
In a pattern binding:
point :: Lens' Atom Point
= lens _point (\ atom newPoint -> atom {_point = newPoint})
It certainly seems to be seeing some difference between f0 vs Functor f.
My code here is no different from that in the tutorial though, and no amount of extensions appears to be saving me from as far as I can tell.
Would anyone have any pointers, perhaps?
;in a one-liner instead. - Carl