shithub: MicroHs

Download patch

ref: 9c14bc26bdb2afc8b8bb9d4be650b7ffef87baf0
parent: 4684ef5c92371024f7a8ae867fd60ff5eb6e98f5
author: Lennart Augustsson <lennart@augustsson.net>
date: Sun Dec 29 11:48:18 EST 2024

Another Data.Text variant

--- a/lib/AllOfLib.hs
+++ b/lib/AllOfLib.hs
@@ -79,6 +79,7 @@
 import Data.STRef
 import Data.String
 import Data.Text
+import Data.Text.Lazy
 import Data.Traversable
 import Data.Tuple
 import Data.Tuple.Instances
--- /dev/null
+++ b/lib/Data/Text/Lazy.hs
@@ -1,0 +1,54 @@
+-- XXX Use coerce of Data.Text
+module Data.Text.Lazy(
+  Text,
+  pack, unpack,
+  empty,
+  append,
+  head,
+  ) where
+import Prelude(); import MiniPrelude hiding(head)
+import Data.Monoid.Internal
+import Data.String
+import qualified Data.ByteString.Internal as BS
+
+newtype Text = T BS.ByteString
+
+instance Eq Text where
+  (==) = cmp (==)
+  (/=) = cmp (/=)
+
+instance Ord Text where
+  (<)  = cmp (<)
+  (<=) = cmp (<=)
+  (>)  = cmp (>)
+  (>=) = cmp (>=)
+
+cmp :: (BS.ByteString -> BS.ByteString -> Bool) -> (Text -> Text -> Bool)
+cmp op (T x) (T y) = op x y
+
+instance Show Text where
+  showsPrec p = showsPrec p . unpack
+
+instance IsString Text where
+  fromString = pack
+
+instance Semigroup Text where
+  (<>) = append
+
+instance Monoid Text where
+  mempty = empty
+
+empty :: Text
+empty = pack []
+
+pack :: String -> Text
+pack s = T (primitive "toUTF8" s)
+
+unpack :: Text -> String
+unpack (T t) = primitive "fromUTF8" t
+
+append :: Text -> Text -> Text
+append (T x) (T y) = T (BS.append x y)
+
+head :: Text -> Char
+head (T t) = primitive "headUTF8" t
--- a/lib/libs.cabal
+++ b/lib/libs.cabal
@@ -85,6 +85,7 @@
         Data.Semigroup
         Data.String
         Data.Text
+        Data.Text.Lazy
         Data.Traversable
         Data.Tuple
         Data.Tuple.Instances