Propositional equality. If a :~: b is inhabited by some terminating
value, then the type a is the same as the type b. To use this equality
in practice, pattern-match on the a :~: b to get out the Refl constructor;
in the body of the pattern-match, the compiler knows that a ~ b.
The data type SourcePos represents source positions. It contains the
name of the source file, a line number, and a column number. Source line
and column positions change intensively during parsing, so we need to
make them strict to avoid memory leaks.
Instances9Eq, Data, Ord, Read, Show, Generic, …
EqSourcePosDefined in megaparsec-9.8.3 · Text.Megaparsec.Pos
DataSourcePosDefined in megaparsec-9.8.3 · Text.Megaparsec.Pos
OrdSourcePosDefined in megaparsec-9.8.3 · Text.Megaparsec.Pos
ReadSourcePosDefined in megaparsec-9.8.3 · Text.Megaparsec.Pos
ShowSourcePosDefined in megaparsec-9.8.3 · Text.Megaparsec.Pos
GenericSourcePosDefined in megaparsec-9.8.3 · Text.Megaparsec.Pos
NFDataSourcePosDefined in megaparsec-9.8.3 · Text.Megaparsec.Pos
PrettySourcePosDefined in plutus-core-1.70.0.0 · PlutusCore.Error · orphan
>>> :{instance TestEquality Tag where testEquality TagInt1 TagInt1 = Just Refl testEquality TagInt1 TagInt2 = Just Refl testEquality TagInt2 TagInt1 = Just Refl testEquality TagInt2 TagInt2 = Just Refl:}
Note: In the future version of some package (to be released around GHC-9.6 / 9.8) the
forall a. Eq (f a) constraint will be added as a constraint to GEq,
with a law relating GEq and Eq:
geq x y = Just Refl ⇒ x == y = True ∀ (x :: f a) (y :: f b)
x == y ≡ isJust (geq x y) ∀ (x, y :: f a)
So, the more useful GEq Tag instance would differentiate between
different constructors:
Example1 expression
>>> :{instance GEq Tag where geq TagInt1 TagInt1 = Just Refl geq TagInt1 TagInt2 = Nothing geq TagInt2 TagInt1 = Nothing geq TagInt2 TagInt2 = Just Refl:}
which is consistent with a derived Eq instance for Tag
Example1 expression
>>> deriving instance Eq (Tag a)
Note that even if a ~ b, the geq (x :: f a) (y :: f b) may
be Nothing (when value terms are inequal).
The consistency of GEq and Eq is easy to check by exhaustion:
Example2 expressions
>>> let checkFwdGEq :: (forall a. Eq (f a), GEq f) => f a -> f b -> Bool; checkFwdGEq x y = case geq x y of Just Refl -> x == y; Nothing -> True>>> (checkFwdGEq TagInt1 TagInt1, checkFwdGEq TagInt1 TagInt2, checkFwdGEq TagInt2 TagInt1, checkFwdGEq TagInt2 TagInt2)(True,True,True,True)
Example2 expressions
>>> let checkBwdGEq :: (Eq (f a), GEq f) => f a -> f a -> Bool; checkBwdGEq x y = if x == y then isJust (geq x y) else isNothing (geq x y)>>> (checkBwdGEq TagInt1 TagInt1, checkBwdGEq TagInt1 TagInt2, checkBwdGEq TagInt2 TagInt1, checkBwdGEq TagInt2 TagInt2)(True,True,True,True)
Show-like class for 1-type-parameter GADTs. GShow t => ... is equivalent to something
like (forall a. Show (t a)) => .... The easiest way to create instances would probably be
to write (or derive) an instance Show (T a), and then simply say:
instance GShow t where gshowsPrec = defaultGshowsPrec
Existential. This is type is useful to hide GADTs' parameters.
Example4 expressions
>>> data Tag :: Type -> Type where TagInt :: Tag Int; TagBool :: Tag Bool>>> instance GShow Tag where gshowsPrec _ TagInt = showString "TagInt"; gshowsPrec _ TagBool = showString "TagBool">>> classify s = case s of "TagInt" -> [mkGReadResult TagInt]; "TagBool" -> [mkGReadResult TagBool]; _ -> []>>> instance GRead Tag where greadsPrec _ s = [ (r, rest) | (con, rest) <- lex s, r <- classify con ]
You can either use PatternSynonyms (available with GHC >= 8.0)
Example2 expressions
>>> let x = Some TagInt>>> xSome TagInt
Example1 expression
>>> case x of { Some TagInt -> "I"; Some TagBool -> "B" } :: String"I"
or you can use functions
Example2 expressions
>>> let y = mkSome TagBool>>> ySome TagBool
Example1 expression
>>> withSome y $ \y' -> case y' of { TagInt -> "I"; TagBool -> "B" } :: String"B"