11{-# OPTIONS_GHC -fno-warn-orphans #-}
22
3- {- - | Type class instances for (->) enabling interpretation of CatExpr as functions.
4- Allows categorical expressions to be evaluated as standard Haskell functions.
5- --}
3+ {- - | Instance-only module for interpreting categorical terms in the (->) category. --}
64
7- module CCC.Hask where
5+ module CCC.Hask () where
86
97import CCC.Cat
108import qualified CCC.Cat as Cat
119
1210instance Monoidal (-> ) where
13- parC f g (x, y) = (f x, g y) -- this could also be implemented as `bimap f g` (imported from Data.Bifunctor)
11+ parC f g (x, y) = (f x, g y)
1412
1513instance Cartesian (-> ) where
1614 fstC (x, _y) = x
@@ -28,11 +26,10 @@ instance NumCat (->) where
2826 addC = uncurry (+)
2927 subC = uncurry (-)
3028 absC = abs
31- -- Need explicit type annotations since BoolLike is polymorphic
32- leqC (x, y) = if x <= y then true else false
33- geqC (x, y) = if x >= y then true else false
34- lesC (x, y) = if x < y then true else false
35- greC (x, y) = if x > y then true else false
29+ leqC = ordPred (<=)
30+ geqC = ordPred (>=)
31+ lesC = ordPred (<)
32+ greC = ordPred (>)
3633
3734instance BoolCat (-> ) where
3835 andC = uncurry (Cat. &&)
@@ -47,6 +44,8 @@ instance IfValCat (->) where
4744 ifValC (test, (t, e)) = if test then t else e
4845
4946instance FixCat (-> ) where
50- -- The step function takes (rec, input) and produces output
51- -- We tie the knot by making rec = fixC step
52- fixC step = let f a = step (f, a) in f
47+ fixC step = let f a = step (f, a) in f
48+
49+ -- BoolLike result type prevents using plain uncurry comparison directly.
50+ ordPred :: (Ord a , BoolLike b ) => (a -> a -> Bool ) -> (a , a ) -> b
51+ ordPred op (x, y) = if op x y then true else false
0 commit comments