{-# LANGUAGE NoRebindableSyntax #-} module Clean.Core( Category(..),Choice(..),Split(..),(:*:),(:+:), first,second,left,right,ifThenElse,fail, module Prelude ) where import Prelude hiding ( Functor(..),Monad(..), sequence,mapM,mapM_,sequence_,(=<<), map,(++),filter,length,sum, (+),(.),id) import qualified Prelude as P ifThenElse b th el = if b then th else el fail = error type a:*:b = (a,b) type a:+:b = Either a b class Category k where id :: k a a (.) :: k b c -> k a b -> k a c instance Category (->) where id = P.id (.) = (P..) class Category k => Choice k where (<|>) :: k a c -> k b c -> k (a:+:b) c infixr 3 <|> instance Choice (->) where (f <|> _) (Left a) = f a (_ <|> g) (Right b) = g b class Category k => Split k where (<#>) :: k a c -> k b d -> k (a,b) (c,d) instance Split (->) where f <#> g = \(a,b) -> (f a,g b) second a = id <#> a first a = a <#> id left a = a <|> id right a = id <|> a