Skip to content

Commit f676962

Browse files
authored
Merge pull request #106 from purescript/more-fn-instances
Add more instances of the form `C b => C (a -> b)`
2 parents 1524f42 + b027d20 commit f676962

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

src/Data/BooleanAlgebra.purs

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ class HeytingAlgebra a <= BooleanAlgebra a
1818

1919
instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
2020
instance booleanAlgebraUnit :: BooleanAlgebra Unit
21+
instance booleanAlgebraFn :: BooleanAlgebra b => BooleanAlgebra (a -> b)

src/Data/CommutativeRing.purs

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ class Ring a <= CommutativeRing a
2020
instance commutativeRingInt :: CommutativeRing Int
2121
instance commutativeRingNumber :: CommutativeRing Number
2222
instance commutativeRingUnit :: CommutativeRing Unit
23+
instance commutativeRingFn :: CommutativeRing b => CommutativeRing (a -> b)

src/Data/Ring.purs

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ instance ringNumber :: Ring Number where
2727
instance ringUnit :: Ring Unit where
2828
sub _ _ = unit
2929

30+
instance ringFn :: Ring b => Ring (a -> b) where
31+
sub f g x = f x - g x
32+
3033
-- | `negate x` can be used as a shorthand for `zero - x`.
3134
negate :: forall a. Ring a => a -> a
3235
negate a = zero - a

src/Data/Semiring.purs

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ instance semiringNumber :: Semiring Number where
4444
mul = numMul
4545
one = 1.0
4646

47+
instance semiringFn :: Semiring b => Semiring (a -> b) where
48+
add f g x = f x + g x
49+
zero = \_ -> zero
50+
mul f g x = f x * g x
51+
one = \_ -> one
52+
4753
instance semiringUnit :: Semiring Unit where
4854
add _ _ = unit
4955
zero = unit

0 commit comments

Comments
 (0)