Closed Icelandjack closed 10 years ago
Simple character formatter and a formatter that formats values as an Int using fromEnum:
Int
fromEnum
ghci> mapM_ TIO.putStrLn [ format (char % " has value " % asInt) ch ch | ch <- "abc" ] a has value 97 b has value 98 c has value 99
As a vague motivator the Rust tutorial has an examples of formatting using what is effectively fromEnum:
println!( "North => {}", North as int );
which would be:
ghci> data Direction = South | North | East | West deriving Enum ghci> format ("North => " % asInt) North "North => 1"
Good one, that Char was missing never occurred to me. I'll merge this and the other one in a bit, have to go shopping, back in 40~.
Char
Rebased and merged.
Simple character formatter and a formatter that formats values as an
Int
usingfromEnum
:As a vague motivator the Rust tutorial has an examples of formatting using what is effectively
fromEnum
:which would be: