Skip to content

Instantly share code, notes, and snippets.

@avaitla
Created December 24, 2011 06:53
Show Gist options
  • Save avaitla/1516620 to your computer and use it in GitHub Desktop.
Save avaitla/1516620 to your computer and use it in GitHub Desktop.
composition of lenses
{-# LANGUAGE TemplateHaskell #-}
import Data.Lens.Template
import Data.Lens.Lazy
data Line = Line {
_lnBeg :: Point
, _lnEnd :: Point
} deriving (Show)
data Point = Point {
_ptX :: Int
, _ptY :: Int
} deriving (Show)
$( makeLenses [''Point, ''Line] )
ptX :: Lens Point Int
lnBeg :: Lens Line Point
compose = ptX . lnBeg
test_lens.hs:18:11:
Couldn't match expected type `b0 -> c0'
with actual type `Lens Point Int'
In the first argument of `(.)', namely `ptX'
In the expression: ptX . lnBeg
In an equation for `compose': compose = ptX . lnBeg
Failed, modules loaded: none.
Note:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment