2020-06-26 18:52:37 +03:00
|
|
|
||| A DYI version of 'string interpolation', mimicking Python 3's 'f-string' syntax
|
2021-01-16 10:03:45 +03:00
|
|
|
||| Not as fancy
|
2020-06-26 18:52:37 +03:00
|
|
|
module Data.String.Interpolation
|
|
|
|
|
|
|
|
import Data.Strings
|
|
|
|
|
|
|
|
namespace Data.String.Interpolation.Basic
|
|
|
|
%inline
|
|
|
|
public export
|
|
|
|
F : List String -> String
|
|
|
|
F strs = concat (strs)
|
|
|
|
|
|
|
|
namespace Data.String.Interpolation.Nested
|
|
|
|
%inline
|
|
|
|
public export
|
|
|
|
F : List (List String) -> String
|
|
|
|
F strss = F (concat strss)
|
|
|
|
|
2021-01-16 10:03:45 +03:00
|
|
|
{- Examples:
|
2020-06-26 18:52:37 +03:00
|
|
|
fstring : String
|
2021-01-16 10:03:45 +03:00
|
|
|
fstring = let apples = "apples" in
|
2020-06-26 18:52:37 +03:00
|
|
|
F["I have some ", apples," here."] --- cf. f"I have some {apples} here."
|
|
|
|
|
|
|
|
multiline : String
|
|
|
|
multiline = let name = "Edwin"
|
|
|
|
profession = "Hacker"
|
2021-01-16 10:03:45 +03:00
|
|
|
affiliation = "the University of St. Andrews" in --- cf.
|
2020-06-26 18:52:37 +03:00
|
|
|
F [["Hi ",name,". " ] --- f"Hi {name}. " \
|
|
|
|
,["You are a ",profession,". "] --- f"You are a {profession}. " \
|
|
|
|
,["You were in ",affiliation,"."] --- f"You were in {affiliation}."
|
|
|
|
]
|
2021-01-16 10:03:45 +03:00
|
|
|
|
2020-06-26 18:52:37 +03:00
|
|
|
-}
|