Skip to content

Commit 24d7979

Browse files
committed
Add partial applicative operators for 'Eq'-like and 'Ord'-like typeclasses.
We already have the ' .foo.' pattern for these typeclasses. However, you often have to use '.foo . pure bar' if 'bar' is a constant. After this change, you can use '.foo bar' instead.
1 parent fadedce commit 24d7979

File tree

3 files changed

+151
-6
lines changed

3 files changed

+151
-6
lines changed

clash-prelude/src/Clash/Explicit/Signal.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ module Clash.Explicit.Signal
259259
, testFor
260260
-- * Type classes
261261
-- ** 'Eq'-like
262-
, (.==.), (./=.)
262+
, (.==.), (.==), (==.), (./=.), (./=), (/=.)
263263
-- ** 'Ord'-like
264-
, (.<.), (.<=.), (.>=.), (.>.)
264+
, (.<.), (.<), (<.), (.<=.), (.<=), (<=.), (.>=.), (.>=), (>=.), (.>.), (.>), (>.)
265265
-- * Bisignal functions
266266
, veryUnsafeToBiSignalIn
267267
, readFromBiSignal

clash-prelude/src/Clash/Signal.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ module Clash.Signal
249249
, testFor
250250
-- * Type classes
251251
-- ** 'Eq'-like
252-
, (.==.), (./=.)
252+
, (.==.), (.==), (==.), (./=.), (./=), (/=.)
253253
-- ** 'Ord'-like
254-
, (.<.), (.<=.), (.>=.), (.>.)
254+
, (.<.), (.<), (<.), (.<=.), (.<=), (<=.), (.>=.), (.>=), (>=.), (.>.), (.>), (>.)
255255
-- * Bisignal functions
256256
, veryUnsafeToBiSignalIn
257257
, readFromBiSignal

clash-prelude/src/Clash/Signal/Internal.hs

+147-2
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ module Clash.Signal.Internal
139139
, testFor
140140
-- * Type classes
141141
-- ** 'Eq'-like
142-
, (.==.), (./=.)
142+
, (.==.), (.==), (==.), (./=.), (./=), (/=.)
143143
-- ** 'Ord'-like
144-
, (.<.), (.<=.), (.>=.), (.>.)
144+
, (.<.), (.<), (<.), (.<=.), (.<=), (<=.), (.>=.), (.>=), (>=.), (.>.), (.>), (>.)
145145
-- ** 'Functor'
146146
, mapSignal#
147147
-- ** 'Applicative'
@@ -1436,6 +1436,30 @@ infix 4 .==.
14361436
(.==.) :: (Eq a, Applicative f) => f a -> f a -> f Bool
14371437
(.==.) = liftA2 (==)
14381438

1439+
infix 4 .==
1440+
-- | The above type is a generalization for:
1441+
--
1442+
-- @
1443+
-- __(.==)__ :: 'Eq' a => 'Clash.Signal.Signal' a -> a -> 'Clash.Signal.Signal' 'Bool'
1444+
-- @
1445+
--
1446+
-- It is a version of ('==') that allows comparing a @'Clash.Signal.Signal' a@ with a
1447+
-- constant @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1448+
(.==) :: (Eq a, Applicative f) => f a -> a -> f Bool
1449+
(.==) a b = fmap (==b) a
1450+
1451+
infix 4 ==.
1452+
-- | The above type is a generalization for:
1453+
--
1454+
-- @
1455+
-- __(==.)__ :: 'Eq' a => a -> 'Clash.Signal.Signal' a -> 'Clash.Signal.Signal' 'Bool'
1456+
-- @
1457+
--
1458+
-- It is a version of ('==') that allows comparing a @'Clash.Signal.Signal' a@ with a
1459+
-- constant @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1460+
(==.) :: (Eq a, Applicative f) => a -> f a -> f Bool
1461+
(==.) a b = fmap (a==) b
1462+
14391463
infix 4 ./=.
14401464
-- | The above type is a generalization for:
14411465
--
@@ -1447,6 +1471,31 @@ infix 4 ./=.
14471471
(./=.) :: (Eq a, Applicative f) => f a -> f a -> f Bool
14481472
(./=.) = liftA2 (/=)
14491473

1474+
infix 4 ./=
1475+
-- | The above type is a generalization for:
1476+
--
1477+
-- @
1478+
-- __(./=)__ :: 'Eq' a => 'Clash.Signal.Signal' a -> a -> 'Clash.Signal.Signal' 'Bool'
1479+
-- @
1480+
--
1481+
-- It is a version of ('/=') that allows comparing a @'Clash.Signal.Signal' a@ with a
1482+
-- constant @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1483+
(./=) :: (Eq a, Applicative f) => f a -> a -> f Bool
1484+
(./=) a b = fmap (/=b) a
1485+
1486+
infix 4 /=.
1487+
-- | The above type is a generalization for:
1488+
--
1489+
-- @
1490+
-- __(/=.)__ :: 'Eq' a => a -> 'Clash.Signal.Signal' a -> 'Clash.Signal.Signal' 'Bool'
1491+
-- @
1492+
--
1493+
-- It is a version of ('/=') that allows comparing a @'Clash.Signal.Signal' a@ with a
1494+
-- constant @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1495+
1496+
(/=.) :: (Eq a, Applicative f) => a -> f a -> f Bool
1497+
(/=.) a b = fmap (a /=) b
1498+
14501499
infix 4 .<.
14511500
-- | The above type is a generalization for:
14521501
--
@@ -1458,6 +1507,30 @@ infix 4 .<.
14581507
(.<.) :: (Ord a, Applicative f) => f a -> f a -> f Bool
14591508
(.<.) = liftA2 (<)
14601509

1510+
infix 4 <.
1511+
-- | The above type is a generalization for:
1512+
--
1513+
-- @
1514+
-- __(<.)__ :: 'Ord' a => a -> 'Clash.Signal.Signal' a -> 'Clash.Signal.Signal' 'Bool'
1515+
-- @
1516+
--
1517+
-- It is a version of ('<') that allows comparing a @'Clash.Signal.Signal' a@ with a constant
1518+
-- @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1519+
(<.) :: (Ord a, Applicative f) => a -> f a -> f Bool
1520+
(<.) a b = fmap (a<) b
1521+
1522+
infix 4 .<
1523+
-- | The above type is a generalization for:
1524+
--
1525+
-- @
1526+
-- __(.<)__ :: 'Ord' a => 'Clash.Signal.Signal' a -> a -> 'Clash.Signal.Signal' 'Bool'
1527+
-- @
1528+
--
1529+
-- It is a version of ('<') that allows comparing a @'Clash.Signal.Signal' a@ with a constant
1530+
-- @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1531+
(.<) :: (Ord a, Applicative f) => f a -> a -> f Bool
1532+
(.<) a b = fmap (<b) a
1533+
14611534
infix 4 .<=.
14621535
-- | The above type is a generalization for:
14631536
--
@@ -1469,6 +1542,30 @@ infix 4 .<=.
14691542
(.<=.) :: (Ord a, Applicative f) => f a -> f a -> f Bool
14701543
(.<=.) = liftA2 (<=)
14711544

1545+
infix 4 .<=
1546+
-- | The above type is a generalization for:
1547+
--
1548+
-- @
1549+
-- __(.<=)__ :: 'Ord' a => 'Clash.Signal.Signal' a -> a -> 'Clash.Signal.Signal' 'Bool'
1550+
-- @
1551+
--
1552+
-- It is a version of ('GHC.TypeNats.<=') that allows comparing a @'Clash.Signal.Signal' a@ with a constant
1553+
-- @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1554+
(.<=) :: (Ord a, Applicative f) => f a -> a -> f Bool
1555+
(.<=) a b = fmap (<=b) a
1556+
1557+
infix 4 <=.
1558+
-- | The above type is a generalization for:
1559+
--
1560+
-- @
1561+
-- __(<=.)__ :: 'Ord' a => a -> 'Clash.Signal.Signal' a -> 'Clash.Signal.Signal' 'Bool'
1562+
-- @
1563+
--
1564+
-- It is a version of ('GHC.TypeNats.<=') that allows comparing a @'Clash.Signal.Signal' a@ with a constant
1565+
-- @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1566+
(<=.) :: (Ord a, Applicative f) => a -> f a -> f Bool
1567+
(<=.) a b = fmap (a<=)b
1568+
14721569
infix 4 .>.
14731570
-- | The above type is a generalization for:
14741571
--
@@ -1480,6 +1577,30 @@ infix 4 .>.
14801577
(.>.) :: (Ord a, Applicative f) => f a -> f a -> f Bool
14811578
(.>.) = liftA2 (>)
14821579

1580+
infix 4 .>
1581+
-- | The above type is a generalization for:
1582+
--
1583+
-- @
1584+
-- __(.>)__ :: 'Ord' a => 'Clash.Signal.Signal' a -> a -> 'Clash.Signal.Signal' 'Bool'
1585+
-- @
1586+
--
1587+
-- It is a version of ('>') that allows comparing a @'Clash.Signal.Signal' a@ with a constant
1588+
-- @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1589+
(.>) :: (Ord a, Applicative f) => f a -> a -> f Bool
1590+
(.>) a b = fmap (>b) a
1591+
1592+
infix 4 >.
1593+
-- | The above type is a generalization for:
1594+
--
1595+
-- @
1596+
-- __(>.)__ :: 'Ord' a => a -> 'Clash.Signal.Signal' a -> 'Clash.Signal.Signal' 'Bool'
1597+
-- @
1598+
--
1599+
-- It is a version of ('>') that allows comparing a @'Clash.Signal.Signal' a@ with a constant
1600+
-- @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1601+
(>.) :: (Ord a, Applicative f) => a -> f a -> f Bool
1602+
(>.) a b = fmap (a>) b
1603+
14831604
infix 4 .>=.
14841605
-- | The above type is a generalization for:
14851606
--
@@ -1491,6 +1612,30 @@ infix 4 .>=.
14911612
(.>=.) :: (Ord a, Applicative f) => f a -> f a -> f Bool
14921613
(.>=.) = liftA2 (>=)
14931614

1615+
infix 4 .>=
1616+
-- | The above type is a generalization for:
1617+
--
1618+
-- @
1619+
-- __(.>=)__ :: 'Ord' a => 'Clash.Signal.Signal' a -> a -> 'Clash.Signal.Signal' 'Bool'
1620+
-- @
1621+
--
1622+
-- It is a version of ('>=') that allows comparing a @'Clash.Signal.Signal' a@ with a constant
1623+
-- @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1624+
(.>=) :: (Ord a, Applicative f) => f a -> a -> f Bool
1625+
(.>=) a b = fmap (>=b) a
1626+
1627+
infix 4 >=.
1628+
-- | The above type is a generalization for:
1629+
--
1630+
-- @
1631+
-- __(>=.)__ :: 'Ord' a => a -> 'Clash.Signal.Signal' a -> 'Clash.Signal.Signal' 'Bool'
1632+
-- @
1633+
--
1634+
-- It is a version of ('>=') that allows comparing a @'Clash.Signal.Signal' a@ with a constant
1635+
-- @a@ and returns a 'Clash.Signal.Signal' of 'Bool'
1636+
(>=.) :: (Ord a, Applicative f) => a -> f a -> f Bool
1637+
(>=.) a b = fmap (a>=) b
1638+
14941639
instance Fractional a => Fractional (Signal dom a) where
14951640
(/) = liftA2 (/)
14961641
recip = fmap recip

0 commit comments

Comments
 (0)