{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Extensible.Example where
import Data.Extensible.Sum
import Data.Maybe
foo :: (a :>|: String) => a -> a
foo x = fromMaybe x $ do
(s :: String) <- peek x
return $ lft $ reverse s
bar :: (a :>|: Int) => a -> a
bar x = fromMaybe x $ do
(i :: Int) <- peek x
return $ lft $ i + 1
foobar :: (String :|: Int) -> (String :|: Int)
foobar = foo . bar
foobar' :: (Char :|: String :|: Int :|: ())
-> (Char :|: String :|: Int :|: ())
foobar' = foo . bar
runExample :: IO ()
runExample = do
let s = "hello" :: String
let i = 1 :: Int
print $ foobar (lft s)
print $ foobar (lft i)