Guest User

Untitled

a guest
Apr 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. {-# LANGUAGE RankNTypes #-}
  2. data Person = Person { _name :: String , _age :: Int } deriving Show
  3.  
  4. makeLenses 'Person
  5.  
  6. example :: Person
  7. example = Person "Bob" 55
  8.  
  9. pry :: Lens' r x -> Iso' r (x -> r,x)
  10. pry l = iso (\r -> (\x -> set l x r, view l r)) (uncurry ($))
  11.  
  12. consName :: Prism' Person (Char,Person)
  13. consName =
  14. pry name . aside _Cons . iso (\(a,(b,c)) -> (b,(a,c))) (\(b,(a,c)) -> (a,(b,c))) . seconding (Control.Lens.from (pry name))
  15.  
  16. -- Λ review consName ('z',example)
  17. -- Person {_name = "zBob", _age = 55}
  18. --
  19. -- Λ preview consName example
  20. -- Just ('B',Person {_name = "ob", _age = 55})
Add Comment
Please, Sign In to add comment