Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE DataKinds #-}
- module Test where
- import Data.WorldPeace (OpenUnion, openUnionLift, relaxOpenUnion)
- import Data.Bifunctor (first)
- data ErrorOne = ErrorOne
- data ErrorTwo = ErrorTwo Int
- data ErrorThree = ErrorThree String
- checkOne :: Int -> Either (OpenUnion '[ErrorOne]) Int
- checkOne x = case x of
- 1 -> Left $ openUnionLift ErrorOne
- otherwise -> Right x
- checkTwo :: Int -> Either (OpenUnion '[ErrorOne, ErrorTwo]) Int
- checkTwo x = case x of
- 2 -> Left $ openUnionLift ErrorOne
- 3 -> Left $ openUnionLift $ ErrorTwo 3
- otherwise -> Right x
- checkThree :: Int -> Either (OpenUnion '[ErrorThree]) Int
- checkThree x = case x of
- 4 -> Left $ openUnionLift $ ErrorThree "error"
- otherwise -> Right x
- checkAll :: Int -> Either (OpenUnion '[ErrorOne, ErrorTwo, ErrorThree]) Int
- checkAll x = do
- a <- first (relaxOpenUnion) $ checkOne x
- b <- first (relaxOpenUnion) $ checkTwo a
- c <- first (relaxOpenUnion) $ checkThree b
- pure b
Add Comment
Please, Sign In to add comment