summaryrefslogtreecommitdiff
path: root/compiler/GHC/Data/FastString.hs
diff options
context:
space:
mode:
authorDaniel Rogozin <daniel.rogozin@serokell.io>2020-05-27 13:35:24 +0300
committerVladislav Zavialov <vlad.z.4096@gmail.com>2021-02-05 20:29:46 +0300
commit96029534f6386b4f64ae3a1f233897d96348a99d (patch)
tree736d188b194ae5df23f1b619beec6a05b7c5aa49 /compiler/GHC/Data/FastString.hs
parentddbdec4128f0e6760c8c7a19344f2f2a7a3314bf (diff)
downloadhaskell-wip/ghc-11342-char-kind.tar.gz
The Char kind (#11342)wip/ghc-11342-char-kind
Co-authored-by: Rinat Stryungis <rinat.stryungis@serokell.io> Implement GHC Proposal #387 * Parse char literals 'x' at the type level * New built-in type families CmpChar, ConsSymbol, UnconsSymbol * New KnownChar class (cf. KnownSymbol and KnownNat) * New SomeChar type (cf. SomeSymbol and SomeNat) * CharTyLit support in template-haskell Updated submodules: binary, haddock. Metric Decrease: T5205 haddock.base Metric Increase: Naperian T13035
Diffstat (limited to 'compiler/GHC/Data/FastString.hs')
-rw-r--r--compiler/GHC/Data/FastString.hs7
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/GHC/Data/FastString.hs b/compiler/GHC/Data/FastString.hs
index 90d1c61594..d9363fe2e4 100644
--- a/compiler/GHC/Data/FastString.hs
+++ b/compiler/GHC/Data/FastString.hs
@@ -72,6 +72,7 @@ module GHC.Data.FastString
-- ** Deconstruction
unpackFS, -- :: FastString -> String
+ unconsFS, -- :: FastString -> Maybe (Char, FastString)
-- ** Encoding
zEncodeFS,
@@ -608,6 +609,12 @@ headFS fs = head $ unpackFS fs
consFS :: Char -> FastString -> FastString
consFS c fs = mkFastString (c : unpackFS fs)
+unconsFS :: FastString -> Maybe (Char, FastString)
+unconsFS fs =
+ case unpackFS fs of
+ [] -> Nothing
+ (chr : str) -> Just (chr, mkFastString str)
+
uniqueOfFS :: FastString -> Int
uniqueOfFS fs = uniq fs