Skip to content

Instantly share code, notes, and snippets.

@worldsayshi
Last active August 29, 2015 14:07
Show Gist options
  • Save worldsayshi/ab65fc49fb2bcaffe573 to your computer and use it in GitHub Desktop.
Save worldsayshi/ab65fc49fb2bcaffe573 to your computer and use it in GitHub Desktop.
How to create lenses for Algebraic Data Types with fclabels
{-# LANGUAGE
TemplateHaskell
#-}
module Label where
import Data.Label.Partial
import Data.Label.Base
import Data.Label.Derive
data Foo a b c = A a
| B b
| C c
(a,b,c) = $(getLabel ''Foo)
test1 = get right (Right "test") -- Just "test"
test2 = get a (A "a") -- Just "a"
{- References:
Problem I ran into:
http://stackoverflow.com/questions/26370141/type-failure-when-using-left-lens-from-fclabels
Overview Blog post from fclabels author:
http://fvisser.nl/post/2013/okt/1/fclabels-2.0.html
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment