ref: 2bd2c35bbfb1d2ed187b532a5a2b0a244d348ecf
parent: 39939c42d445b04beba5a27528b2b9fd002e0319
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Sun Oct 22 11:15:12 EDT 2023
Add singleton
--- a/src/MicroHs/IdentMap.hs
+++ b/src/MicroHs/IdentMap.hs
@@ -6,7 +6,7 @@
--
module MicroHs.IdentMap(
Map,
- empty,
+ empty, singleton,
insertWith, insert,
fromListWith, fromList,
delete,
@@ -14,7 +14,7 @@
size,
toList, elems,
) where
-import Prelude --Xhiding(lookup)
+import Prelude hiding(lookup)
import MicroHs.Ident
--Ximport Compat
@@ -31,6 +31,9 @@
empty :: forall a . Map a
empty = Nil
+
+singleton :: forall a . Ident -> a -> Map a
+singleton i a = One i a
elems :: forall v . Map v -> [v]
elems = map snd . toList
--- /dev/null
+++ b/tests/Class.hs
@@ -1,0 +1,44 @@
+module Class(main) where
+import Prelude
+
+class Eqq a where
+ (===) :: a -> a -> Bool
+ (/==) :: a -> a -> Bool
+ x /== y = not (x === y)
+
+instance Eqq Int where
+ (===) = (==)
+
+instance Eqq Char where
+ (===) = eqChar
+
+instance forall a . Eqq a => Eqq [a] where
+ [] === [] = True
+ (x:xs) === (y:ys) = x === y && xs === ys
+ _ === _ = False
+
+class (Eqq a) => Ordd a where
+ (<==) :: a -> a -> Bool
+
+instance Ordd Int where
+ (<==) = (<=)
+
+instance forall a b . (Eqq a, Eqq b) => Eqq (a, b) where
+ (a, b) === (a', b') = a === a' && b === b'
+
+f :: forall a . Eqq a => a -> Bool
+f x = x === x
+
+g :: forall a . Ordd a => a -> Bool
+g x = x /== x
+
+h :: forall a b . (Eqq a, Eqq b) => a -> b -> Bool
+h a b = a === a && b === b
+
+main :: IO ()
+main = do
+ putStrLn $ showBool $ f 5
+ putStrLn $ showBool $ g 5
+ putStrLn $ showBool $ h 5 'a'
+ putStrLn $ showBool $ f [88]
+ putStrLn $ showBool $ f (1, 'a')
--- /dev/null
+++ b/tests/Class.ref
@@ -1,0 +1,5 @@
+True
+False
+True
+True
+True
--
⑨