Platform
MisoString
MisoString is miso's canonical string type, chosen to minimise copying between the Haskell and JavaScript heaps.
- JS / WASM backends —
MisoStringisJSString, a direct reference to a JavaScript string; no marshalling cost when passing to the DOM or FFI. - Server / vanilla GHC (
-fssr) —MisoStringisData.Text.
Use MisoString anywhere you would otherwise reach for String or Text in a miso application. See Miso.String for the full API (it re-exports the underlying module wholesale).
Converting to MisoString
ms (shorthand for toMisoString) converts any type with a ToMisoString instance:
ms "hello" -- String -> MisoString
ms (42 :: Int) -- Int -> MisoString
ms (3.14 :: Double) -- Double -> MisoString
ms myText -- Text -> MisoStringInstances exist for String, strict and lazy Text, ByteString, Int, Word, Double, Float and Char.
Converting from MisoString
fromMisoString parses back into another type (throwing on failure); fromMisoStringEither is the safe variant:
fromMisoString "42" :: Int -- 42
fromMisoString "3.14" :: Double -- 3.14
fromMisoStringEither s :: Either String IntMultiline literals
GHC's MultilineStrings extension (9.12+) works directly with MisoString — this site uses it for all of its code samples:
{-# LANGUAGE MultilineStrings #-}
snippet :: MisoString
snippet = """
line one
line two
"""On older compilers, Miso.String.QQ provides the misoString quasi-quoter for the same purpose.