Skip to content

Commit c4adbce

Browse files
author
Thomas Mahler
committed
simplify
1 parent 2767bdb commit c4adbce

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/CCC/Compiler.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE GADTs #-}
21
{-# LANGUAGE LambdaCase #-}
32

43
{-- | Compilation from lambda calculus expressions (Expr) and environments
@@ -11,7 +10,14 @@
1110
- Function applications
1211
--}
1312

14-
module CCC.Compiler where
13+
module CCC.Compiler
14+
( Value,
15+
evalExpr,
16+
compileNumExpr,
17+
compileEnvironment,
18+
tryCompileVar,
19+
compileNumericBindings
20+
) where
1521

1622
import CCC.CatExpr (CatExpr (..))
1723
import CCC.Rewrite (simplify)
@@ -150,7 +156,7 @@ tryCompileVar env name = case lookup name env of
150156
-- Collects successful numeric compilations and reports failures.
151157
compileNumericBindings :: Environment -> ([(String, String)], [String])
152158
compileNumericBindings env =
153-
let results = map (\(name, expr) -> (name, tryCompileVar env name)) env
159+
let results = map (\(name, _expr) -> (name, tryCompileVar env name)) env
154160
successes = [(n, show m) | (n, Right m) <- results]
155161
failures = [e | (_, Left e) <- results]
156162
in (successes, failures)

src/CCC/Hask.hs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
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

97
import CCC.Cat
108
import qualified CCC.Cat as Cat
119

1210
instance 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

1513
instance 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

3734
instance 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

4946
instance 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

Comments
 (0)