Re: [GHC] #5218: Add unpackCStringLen# to create Strings from string literals

#5218: Add unpackCStringLen# to create Strings from string literals -------------------------------------+------------------------------------- Reporter: tibbe | Owner: thoughtpolice Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.0.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Runtime | Unknown/Multiple performance bug | Test Case: Blocked By: | Blocking: Related Tickets: #5877 #10064 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Mathnerd314): I have yet another proposal, namely to add low-level construction methods to `IsString`: {{{#!hs class IsString a where fromString :: String -> a -- as before fromString_asc# :: Addr# -> Int# -> a fromString_asc# a _ = fromString (unpackCString# a) fromString_utf8# :: Addr# -> Int# -> a fromString_utf8# a _ = fromString (unpackCStringUtf8# a) fromString_raw# :: Addr# -> Int# -> a fromString_raw# a i = fromString (map chr (addrToWord8List a i) }}} The `String` instance would have `fromString = id`, while the `ByteString` instance would do zero-copy construction with the length information. ASCII literals would use _asc, UTF-8 literals would use _utf8, and primitive string literals would use _raw. Then `"x"# :: ByteString` would typecheck and work as expected. The only tricky part is preserving `"x"# :: Addr#` (which would be expanded to `fromString_raw# "x"# 1# :: Addr#`). It doesn't seem like `instance IsString Addr#` would be suitable. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/5218#comment:39 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC