ref: 638e7ca702c9c27bd58a72d68b0862c86e68c25b
parent: 69c8b971023710b43def1408f09e74d72d516a77
author: Lennart Augustsson <lennart@augustsson.net>
date: Thu Nov 2 09:20:28 EDT 2023
More Show instances
--- a/Makefile
+++ b/Makefile
@@ -49,16 +49,17 @@
$(GHCB) -c ghc/Data/Bool_Type.hs
$(GHCB) -c ghc/Data/Char_Type.hs
$(GHCB) -c ghc/Data/List_Type.hs
+ $(GHCB) -c lib/Data/Maybe_Type.hs
$(GHCB) -c ghc/Data/Ordering_Type.hs
$(GHCB) -c ghc/Data/Double.hs
$(GHCB) -c ghc/PrimTable.hs
$(GHCC) -c lib/Control/Error.hs
$(GHCC) -c lib/Data/Eq.hs
- $(GHCC) -c lib/Data/Ord.hs
$(GHCC) -c lib/Text/Show.hs
+ $(GHCC) -c lib/Data/Ord.hs
$(GHCC) -c lib/Data/Bool.hs
- $(GHCC) -c lib/Data/Tuple.hs
$(GHCC) -c lib/Data/Function.hs
+ $(GHCC) -c lib/Data/Tuple.hs
$(GHCC) -c lib/Data/Functor.hs
$(GHCC) -c lib/Control/Applicative.hs
$(GHCC) -c lib/Control/Monad.hs
@@ -66,9 +67,9 @@
$(GHCC) -c lib/Data/Double.hs
$(GHCC) -c lib/Data/Char.hs
$(GHCC) -c lib/Data/Either.hs
- $(GHCC) -c lib/Data/Maybe.hs
$(GHCC) -c lib/Data/Ord.hs
$(GHCC) -c lib/Data/List.hs
+ $(GHCC) -c lib/Data/Maybe.hs
$(GHCC) -c lib/Control/Alternative.hs
$(GHCC) -c lib/Text/String.hs
$(GHCC) -c lib/Data/Word.hs
--- a/comb/mhs.comb
+++ b/comb/mhs.comb
@@ -1,3 +1,3 @@
v4.0
-1186
-((A :0 ((B (B (B (B C)))) ((B (B (B C))) ((B (B C)) P)))) ((A :1 (T (BK (BK (BK K))))) ((A :2 (T (K (BK (BK K))))) ((A :3 (T (K (K (BK K))))) ((A :4 (T (K (K (K K))))) ((A :5 (T (K (K (K A))))) ((A :6 (K (noDefault "Alternative.empty"))) ((A :7 (K (noDefault "Alternative.<|>"))) ((A :8 ((S (((S' S') ((B _14) _1)) (((C' _131) ((B _12) _1)) _241))) _5)) ((A :9 ((S (((S' C') _3) _4)) (((C' _13) _1) _240))) ((A :10 (((S' P) _2) (((C' _13) _1) _944))) ((A :11 ((B (B (B (B C)))) ((B (B (B C))) ((B (B C)) P)))) ((A :12 (T (BK (BK (BK K))))) ((A :13 (T (K (BK (BK K))))) ((A :14 (T (K (K (BK K))))) ((A :15 (T (K (K (K K))))) ((A :16 (T (K (K (K A))))) ((A :17 (K (noDefault "Applicative.pure"))) ((A :18 (K (noDefault "Applicative.<*>"))) ((A :19 (((S' B) _14) (((C' _128) _12) _120))) ((A :20 (((S' B) _14) (((C' _131) _12) _121))) ((A :21 _1016) ((A :22 ((B _1058) _21)) ((A :23 (((S' _1058) _21) I)) ((A :24 _986) ((A :25 (_24 "undefined")) ((A :26 I) ((A :27 (((C' B) _1015) ((C _119) _26))) ((A :28 (((C' _27) ((_127 _1029) _109)) ((_119 (_34 _1031)) _108))) ((A :29 ((B ((S _1058) (_34 _1031))) _24)) ((A :30 ((B (B (B C))) ((B (B C)) P))) ((A :31 (T (BK (BK K)))) ((A :32 (T (K (BK K)))) ((A :33 (T (K (K K)))) ((A :34 (T (K (K A)))) ((A :35 (K (noDefault "Monad.>>="))) ((A :36 (((C' (C' B)) _32) K)) ((A :37 ((B _13) _31)) ((A :38 (((S' (C' B)) _32) (((S' (C' B)) _32) (B' _34)))) ((A :39 P) ((A :40 (T K)) ((A :41 (T A)) ((A :42 (K _24)) ((A :43 ((B (B Y)) (((S' B) (B' ((B P) ((C _34) _240)))) (((S' (C' B)) ((B (B (C' B))) (B' _32))) (((S' (C' (C' B))) (B' _32)) (((C' B) (B' _34)) _241)))))) ((A :44 ((B (B Y)) (((S' B) (B' ((B P) ((C _34) _944)))) (((C' (C' B)) ((B (B (C' B))) (B' _32))) BK)))) ((A :45 ((B T) ((C _34) _944))) ((A :46 ((C _43) _120)) ((A :47 ((B _122) _32)) ((A :48 ((B C) ((B C') _32))) ((A :49 ((B _122) _48)) ((A :50 T) ((A :51 ((_126 ((B (B (_117 _50))) ((B ((C' C) _54)) (B P)))) (_130 _51))) ((A :52 (((((_11 _51) ((B (_117 _50)) P)) (_38 _53)) ((B (B (_117 _50))) (((C' B) ((B C) _54)) (BK _54)))) (_20 _52))) ((A :53 ((((_30 _52) ((B (B (_117 _50))) (((C' B) ((B C) _54)) (B _54)))) (_15 _52)) (_13 _52))) ((A :54 (T I)) ((A :55 ((B (_119 _271)) _54)) ((A :56 ((B (_117 _50)) (B (P _944)))) ((A :57 ((B (_117 _50)) (BK (P _944)))) ((A :58 ((_117 _50) ((S P) I))) ((A :59 ((B (_117 _50)) ((C (S' P)) I))) ((A :60 ((_112 ((C ((C S') _63)) I)) (_116 _60))) ((A :61 (R _69)) ((A :62 (T _68)) ((A :63 ((P _69) _68)) ((A :64 _69) ((A :65 ((C ((C S') _63)) I)) ((A :66 ((C S) _63)) ((A :67 (((_1156 (K ((P (_1165 "False")) (_1165 "True")))) (_1161 _67)) (_1162 _67))) ((A :68 K) ((A :69 A) ((A :70 ((_112 _980) _981)) ((A :71 ((((((((_250 _70) (_259 _71)) _982) _983) _984) _985) (_264 _71)) (_265 _71))) ((A :72 ((_112 _990) (_116 _72))) ((A :73 ((((((((_250 _72) _989) (((C' (C' (_113 _266))) _989) _268)) (((C' (C' (_114 _266))) _989) _270)) (((C' (C' (_113 _266))) _989) _270)) (((C' (C' (_114 _266))) _989) _270)) (_264 _73)) (_265 _73))) ((A :74 _991) ((A :75 _992) ((A :76 (((S' _62) (_983 #97)) ((C _983) #122))) ((A :77 (((S' _62) (_983 #65)) ((C _983) #90))) ((A :78 (((S' _61) _76) _77)) ((A :79 (((S' _62) (_983 #48)) ((C _983) #57))) ((A :80 (((S' _61) _78) _79)) ((A :81 (((S' _62) (_983 #32)) ((C _983) #126))) ((A :82 (((S' _61) ((C (_113 _70)) #32)) (((S' _61) ((C (_113 _70)) #9)) ((C (_113 _70)) #10)))) ((A :83 ((S ((S (((S' _62) (_983 #65)) ((C _983) #90))) (_69 (((noMatch "lib/Data/Char.hs") #3) #8)))) ((B _74) (((C' _132) (((C' _133) _75) (_75 #65))) (_75 #97))))) ((A :84 ((S ((S (((S' _62) (_983 #97)) ((C _983) #97))) (_69 (((noMatch "lib/Data/Char.hs") #3) #8)))) ((B _74) (((C' _132) (((C' _133) _75) (_75 #97))) (_75 #65))))) ((A :85 (((_1156 (K ((B (_119 (_1164 #39))) (((C' _119) ((B _1165) _86)) (_1164 #39))))) (_1161 _85)) ((B (_119 (_1164 #34))) (Y ((B (P (_1164 #34))) ((C' B) ((B _119) ((B _1165) _86)))))))) ((A :86 (((C' Y) (((S' B) ((B P) ((S ((C _81) "XXX")) ((C O) K)))) ((B (B (C B))) (B' ((B C) (C (_113 _70))))))) ((O ((P #10) "\92&n")) ((O ((P #13) "\92&r")) ((O ((P #9) "\92&t")) ((O ((P #8) "\92&b")) ((O ((P #92)
\ No newline at end of file
+1195
+((A :0 ((B (B (B (B C)))) ((B (B (B C))) ((B (B C)) P)))) ((A :1 (T (BK (BK (BK K))))) ((A :2 (T (K (BK (BK K))))) ((A :3 (T (K (K (BK K))))) ((A :4 (T (K (K (K K))))) ((A :5 (T (K (K (K A))))) ((A :6 (K (noDefault "Alternative.empty"))) ((A :7 (K (noDefault "Alternative.<|>"))) ((A :8 ((S (((S' S') ((B _14) _1)) (((C' _132) ((B _12) _1)) _240))) _5)) ((A :9 ((S (((S' C') _3) _4)) (((C' _13) _1) _239))) ((A :10 (((S' P) _2) (((C' _13) _1) _953))) ((A :11 ((B (B (B (B C)))) ((B (B (B C))) ((B (B C)) P)))) ((A :12 (T (BK (BK (BK K))))) ((A :13 (T (K (BK (BK K))))) ((A :14 (T (K (K (BK K))))) ((A :15 (T (K (K (K K))))) ((A :16 (T (K (K (K A))))) ((A :17 (K (noDefault "Applicative.pure"))) ((A :18 (K (noDefault "Applicative.<*>"))) ((A :19 (((S' B) _14) (((C' _129) _12) _121))) ((A :20 (((S' B) _14) (((C' _132) _12) _122))) ((A :21 _1025) ((A :22 ((B _1067) _21)) ((A :23 (((S' _1067) _21) I)) ((A :24 _995) ((A :25 (_24 "undefined")) ((A :26 I) ((A :27 (((C' B) _1024) ((C _120) _26))) ((A :28 (((C' _27) ((_128 _1038) _109)) ((_120 (_34 _1040)) _108))) ((A :29 ((B ((S _1067) (_34 _1040))) _24)) ((A :30 ((B (B (B C))) ((B (B C)) P))) ((A :31 (T (BK (BK K)))) ((A :32 (T (K (BK K)))) ((A :33 (T (K (K K)))) ((A :34 (T (K (K A)))) ((A :35 (K (noDefault "Monad.>>="))) ((A :36 (((C' (C' B)) _32) K)) ((A :37 ((B _13) _31)) ((A :38 (((S' (C' B)) _32) (((S' (C' B)) _32) (B' _34)))) ((A :39 P) ((A :40 (T K)) ((A :41 (T A)) ((A :42 (K _24)) ((A :43 ((B (B Y)) (((S' B) (B' ((B P) ((C _34) _239)))) (((S' (C' B)) ((B (B (C' B))) (B' _32))) (((S' (C' (C' B))) (B' _32)) (((C' B) (B' _34)) _240)))))) ((A :44 ((B (B Y)) (((S' B) (B' ((B P) ((C _34) _953)))) (((C' (C' B)) ((B (B (C' B))) (B' _32))) BK)))) ((A :45 ((B T) ((C _34) _953))) ((A :46 ((C _43) _121)) ((A :47 ((B _123) _32)) ((A :48 ((B C) ((B C') _32))) ((A :49 ((B _123) _48)) ((A :50 T) ((A :51 ((_127 ((B (B (_118 _50))) ((B ((C' C) _54)) (B P)))) (_131 _51))) ((A :52 (((((_11 _51) ((B (_118 _50)) P)) (_38 _53)) ((B (B (_118 _50))) (((C' B) ((B C) _54)) (BK _54)))) (_20 _52))) ((A :53 ((((_30 _52) ((B (B (_118 _50))) (((C' B) ((B C) _54)) (B _54)))) (_15 _52)) (_13 _52))) ((A :54 (T I)) ((A :55 ((B (_120 _274)) _54)) ((A :56 ((B (_118 _50)) (B (P _953)))) ((A :57 ((B (_118 _50)) (BK (P _953)))) ((A :58 ((_118 _50) ((S P) I))) ((A :59 ((B (_118 _50)) ((C (S' P)) I))) ((A :60 ((_113 ((C ((C S') _63)) I)) (_117 _60))) ((A :61 (R _69)) ((A :62 (T _68)) ((A :63 ((P _69) _68)) ((A :64 _69) ((A :65 ((C ((C S') _63)) I)) ((A :66 ((C S) _63)) ((A :67 (((_1165 (K ((P (_1174 "False")) (_1174 "True")))) (_1170 _67)) (_1171 _67))) ((A :68 K) ((A :69 A) ((A :70 ((_113 _989) _990)) ((A :71 ((((((((_252 _70) (_261 _71)) _991) _992) _993) _994) (_266 _71)) (_267 _71))) ((A :72 ((_113 _999) (_117 _72))) ((A :73 ((((((((_252 _72) _998) (((C' (C' (_114 _268))) _998) _271)) (((C' (C' (_115 _268))) _998) _273)) (((C' (C' (_114 _268))) _998) _273)) (((C' (C' (_115 _268))) _998) _273)) (_266 _73)) (_267 _73))) ((A :74 _1000) ((A :75 _1001) ((A :76 (((S' _62) (_992 #97)) ((C _992) #122))) ((A :77 (((S' _62) (_992 #65)) ((C _992) #90))) ((A :78 (((S' _61) _76) _77)) ((A :79 (((S' _62) (_992 #48)) ((C _992) #57))) ((A :80 (((S' _61) _78) _79)) ((A :81 (((S' _62) (_992 #32)) ((C _992) #126))) ((A :82 (((S' _61) ((C (_114 _70)) #32)) (((S' _61) ((C (_114 _70)) #9)) ((C (_114 _70)) #10)))) ((A :83 ((S ((S (((S' _62) (_992 #65)) ((C _992) #90))) (_69 (((noMatch "lib/Data/Char.hs") #3) #8)))) ((B _74) (((C' _133) (((C' _134) _75) (_75 #65))) (_75 #97))))) ((A :84 ((S ((S (((S' _62) (_992 #97)) ((C _992) #97))) (_69 (((noMatch "lib/Data/Char.hs") #3) #8)))) ((B _74) (((C' _133) (((C' _134) _75) (_75 #97))) (_75 #65))))) ((A :85 (((_1165 (K ((B (_120 (_1173 #39))) (((C' _120) ((B _1174) _86)) (_1173 #39))))) (_1170 _85)) ((B (_120 (_1173 #34))) (Y ((B (P (_1173 #34))) ((C' B) ((B _120) ((B _1174) _86)))))))) ((A :86 (((C' Y) (((S' B) ((B P) ((S ((C _81) "XXX")) ((C O) K)))) ((B (B (C B))) (B' ((B C) (C (_114 _70))))))) ((O ((P #10) "\92&n")) ((O ((P #13) "\92&r")) ((O ((P #9) "\92&t")) ((O ((P #8) "\92&b")) ((O ((P #9
\ No newline at end of file
--- a/lib/Data/Either.hs
+++ b/lib/Data/Either.hs
@@ -4,6 +4,10 @@
import Primitives
import Data.Bool
import Data.Eq
+import Data.Function
+import Data.Int
+import Data.Ord
+import Text.Show
data Either a b = Left a | Right b
@@ -15,3 +19,7 @@
either :: forall a b r . (a -> r) -> (b -> r) -> Either a b -> r
either f _ (Left a) = f a
either _ f (Right b) = f b
+
+instance forall a b . (Show a, Show b) => Show (Either a b) where
+ showsPrec p (Left a) = showParen (p>=11) (showString "Left " . showsPrec 11 a)
+ showsPrec p (Right b) = showParen (p>=11) (showString "Right " . showsPrec 11 b)
--- a/lib/Data/Function.hs
+++ b/lib/Data/Function.hs
@@ -2,7 +2,7 @@
-- See LICENSE file for full license.
module Data.Function(module Data.Function) where
import Primitives
-import Data.Tuple
+--import Data.Tuple
infixr 0 $
($) :: forall a b . (a -> b) -> a -> b
@@ -29,7 +29,7 @@
fix = primFix
uncurry :: forall a b c . (a -> b -> c) -> (a, b) -> c
-uncurry f ab = f (fst ab) (snd ab)
+uncurry f (a, b) = f a b -- XXX not lazy
infixl 0 `on`
on :: forall a b c . (a -> a -> b) -> (c -> a) -> (c -> c -> b)
--- a/lib/Data/Identity.hs
+++ b/lib/Data/Identity.hs
@@ -1,8 +1,12 @@
module Data.Identity(Data.Identity) where
import Primitives
-import Data.Functor
import Control.Applicative
import Control.Monad
+import Data.Function
+import Data.Functor
+import Data.Int
+import Data.Ord
+import Text.Show
newtype Identity a = Identity a
@@ -15,3 +19,6 @@
instance Monad Identity where
Identity a >>= f = f a
+
+instance forall a . (Show a) => Show (Identity a) where
+ showsPrec p (Identity a) = showParen (p >= 11) (showString "Identity " . showsPrec 11 a)
--- a/lib/Data/Integer.hs
+++ b/lib/Data/Integer.hs
@@ -39,6 +39,9 @@
instance Eq Integer where
x == y = isZero (subI x y)
+instance Show Integer where
+ show i = showInteger i
+
isZero :: Integer -> Bool
isZero (I _ ds) = null ds
--- a/lib/Data/List.hs
+++ b/lib/Data/List.hs
@@ -15,7 +15,7 @@
import Data.Int
import Data.List_Type
import Data.Ord
-import Data.Maybe
+import Data.Maybe_Type
import Data.Tuple
import Text.Show
@@ -347,17 +347,6 @@
sortLE le (x:xs) =
case partition (le x) xs of
(ge, lt) -> sortLE le lt ++ (x : sortLE le ge)
-
-mapMaybe :: forall a b . (a -> Maybe b) -> [a] -> [b]
-mapMaybe _ [] = []
-mapMaybe f (a:as) =
- case f a of
- Nothing -> mapMaybe f as
- Just b -> b : mapMaybe f as
-
-maybeToList :: forall a . Maybe a -> [a]
-maybeToList Nothing = []
-maybeToList (Just a) = [a]
last :: forall a . [a] -> a
last [] = error "last: []"
--- a/lib/Data/Maybe.hs
+++ b/lib/Data/Maybe.hs
@@ -1,11 +1,17 @@
-- Copyright 2023 Lennart Augustsson
-- See LICENSE file for full license.
-module Data.Maybe(module Data.Maybe) where
+module Data.Maybe(module Data.Maybe, module Data.Maybe_Type) where
import Primitives
import Data.Bool
+import Data.Char
import Data.Eq
+import Data.Function
+import Data.Int
+import Data.List
+import Data.Maybe_Type
+import Data.Ord
+import Text.Show
-data Maybe a = Nothing | Just a
instance forall a . Eq a => Eq (Maybe a) where
Nothing == Nothing = True
@@ -12,6 +18,12 @@
Just x == Just x' = x == x'
_ == _ = False
+instance forall a . (Show a) => Show (Maybe a) where
+ showsPrec _ Nothing = showsPrec 0 "Nothing"
+ showsPrec p (Just a) = showParen (p >= 11) (showString "Just " . showsPrec 11 a)
+
+-- XXX instance Monad Maybe
+
maybe :: forall a r . r -> (a -> r) -> Maybe a -> r
maybe r _ Nothing = r
maybe _ f (Just a) = f a
@@ -27,7 +39,14 @@
isJust Nothing = False
isJust (Just _) = True
-{--mapMaybe is in Data.List to avoid recursive modules
-maybeToList is in Data.List to avoid recursive modules
--}
+mapMaybe :: forall a b . (a -> Maybe b) -> [a] -> [b]
+mapMaybe _ [] = []
+mapMaybe f (a:as) =
+ case f a of
+ Nothing -> mapMaybe f as
+ Just b -> b : mapMaybe f as
+
+maybeToList :: forall a . Maybe a -> [a]
+maybeToList Nothing = []
+maybeToList (Just a) = [a]
+
--- a/lib/Data/Ord.hs
+++ b/lib/Data/Ord.hs
@@ -6,6 +6,7 @@
import Data.Bool_Type
import Data.Ordering_Type
import Data.Eq
+import Text.Show
infix 4 <,<=,>,>=
@@ -35,3 +36,7 @@
isEQ EQ = True
isEQ _ = False
+instance Show Ordering where
+ showsPrec _ LT = showString "LT"
+ showsPrec _ EQ = showString "EQ"
+ showsPrec _ GT = showString "GT"
--- a/lib/Data/Tuple.hs
+++ b/lib/Data/Tuple.hs
@@ -8,6 +8,8 @@
import Primitives -- for ()
import Data.Bool
import Data.Eq
+import Data.Function
+import Text.Show
--data (a,b) = (a,b) -- all tuples are built in
--data (a,b,c) = (a,b,c)
@@ -30,3 +32,12 @@
instance forall a b c d . (Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d) where
(a1, b1, c1, d1) == (a2, b2, c2, d2) = a1 == a2 && b1 == b2 && c1 == c2 && d1 == d2
+
+instance Show () where
+ showsPrec _ () = showString "()"
+
+instance forall a b . (Show a, Show b) => Show (a, b) where
+ showsPrec _ (a, b) = showParen True (showsPrec 0 a . showString "," . showsPrec 0 b)
+
+instance forall a b c . (Show a, Show b, Show c) => Show (a, b, c) where
+ showsPrec _ (a, b, c) = showParen True (showsPrec 0 a . showString "," . showsPrec 0 b . showString "," . showsPrec 0 c)
--
⑨