Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 5ccf337

Browse files
committed
Define an Ord1 instance for Python.
1 parent 4ed026b commit 5ccf337

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

  • semantic-analysis/src/Analysis/Syntax

semantic-analysis/src/Analysis/Syntax/Python.hs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import Analysis.VM
3535
import Control.Effect.Labelled
3636
import Control.Effect.Reader
3737
import Data.Function (fix)
38-
import Data.Functor.Classes (Eq1 (..))
38+
import Data.Functor.Classes (Eq1 (..), Ord1 (..))
3939
import Data.List.NonEmpty (NonEmpty)
4040
import Data.Text (Text)
4141
import Source.Span (Span)
@@ -132,6 +132,34 @@ instance Eq1 Python where
132132
(Locate' s1, Locate' s2) -> s1 == s2
133133
_ -> False
134134

135+
instance Ord1 Python where
136+
liftCompare _ a b = case (a, b) of
137+
(Noop', Noop') -> EQ
138+
(Noop', _) -> LT
139+
(Iff', Iff') -> EQ
140+
(Iff', _) -> LT
141+
(Bool' b1, Bool' b2) -> compare b1 b2
142+
(Bool' _, _) -> LT
143+
(String' s1, String' s2) -> compare s1 s2
144+
(String' _, _) -> LT
145+
(Throw', Throw') -> EQ
146+
(Throw', _) -> LT
147+
(Let' n1, Let' n2) -> compare n1 n2
148+
(Let' _, _) -> LT
149+
((:>>>), (:>>>)) -> EQ
150+
((:>>>), _) -> LT
151+
(Import' i1, Import' i2) -> compare i1 i2
152+
(Import' _, _) -> LT
153+
(Function' n1 as1, Function' n2 as2) -> compare n1 n2 <> compare as1 as2
154+
(Function' _ _, _) -> LT
155+
(Call', Call') -> EQ
156+
(Call', _) -> LT
157+
(ANil', ANil') -> EQ
158+
(ANil', _) -> LT
159+
(ACons', ACons') -> EQ
160+
(ACons', _) -> LT
161+
(Locate' s1, Locate' s2) -> compare s1 s2
162+
(Locate' _, _) -> LT
135163

136164

137165
-- Abstract interpretation

0 commit comments

Comments
 (0)