Skip to content

Commit

Permalink
Add Eq, Ord to Defn combinators
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Aug 21, 2024
1 parent 5071528 commit 821ec04
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions unison-core/src/Unison/Util/Defn.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,28 @@ module Unison.Util.Defn
)
where

import Data.Bifoldable (Bifoldable (..))
import Data.Bifunctor (Bifunctor (..))
import Data.Bitraversable (Bitraversable (..))
import GHC.Generics (Generic)

-- | A "definition" is either a term or a type.
data Defn term typ
= TermDefn term
| TypeDefn typ
deriving stock (Generic, Functor, Foldable, Traversable, Show, Eq, Ord)

instance Bifunctor Defn where
bimap f g = \case
TermDefn x -> TermDefn (f x)
TypeDefn y -> TypeDefn (g y)

instance Bifoldable Defn where
bifoldMap f g = \case
TermDefn x -> f x
TypeDefn y -> g y

instance Bitraversable Defn where
bitraverse f g = \case
TermDefn x -> TermDefn <$> f x
TypeDefn y -> TypeDefn <$> g y
2 changes: 1 addition & 1 deletion unison-core/src/Unison/Util/Defns.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ data Defns terms types = Defns
{ terms :: terms,
types :: types
}
deriving stock (Generic, Functor, Show)
deriving stock (Generic, Functor, Show, Eq, Ord)
deriving (Monoid, Semigroup) via GenericSemigroupMonoid (Defns terms types)

instance Bifoldable Defns where
Expand Down

0 comments on commit 821ec04

Please sign in to comment.