Skip to content

Instantly share code, notes, and snippets.

@sebastiaanvisser
Created December 27, 2010 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sebastiaanvisser/756138 to your computer and use it in GitHub Desktop.
Save sebastiaanvisser/756138 to your computer and use it in GitHub Desktop.
Tying the knot with fclabels.
{-# LANGUAGE
TypeOperators
, TemplateHaskell
#-}
module Tie where
import Prelude hiding ((.), id)
import Control.Category
import Data.Record.Label
-- Tying the knot for two values with two labels indicating the positions to tie.
tie :: a -> b -> (a :-> b) -> (b :-> a) -> (a, b)
tie a b f g =
let a' = setL f b' a
b' = setL g a' b
in (a', b')
-- Simple test.
data Person = Person
{ _name :: String
, _job :: Job
}
data Job = Job
{ _title :: String
, _who :: Person
}
$(mkLabels [''Person])
$(mkLabels [''Job])
me :: Person
myJob :: Job
(me, myJob) = tie (Person "Sebas" undefined) (Job "Software Engineer" undefined) job who
test :: String
test = getL (title . job . who . job . who . job . who . job) me
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment