Last active
August 29, 2015 14:07
-
-
Save worldsayshi/ab65fc49fb2bcaffe573 to your computer and use it in GitHub Desktop.
How to create lenses for Algebraic Data Types with fclabels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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