I've made a calculator in haskell which I run from within GHCi. However since the final number can be an integer or double I've made the type declaration
calc :: String -> Either Integer Double
However the output of the function always has either left or right in front of it for example
Left 7
Right 8.4
Is there a way I can stop the left and right being printed?
When you evaluate this function, GHCi automatically calls putStrLn . show on the result. It is the show function for Either Integer Double which is adding the Left and Right strings.
To avoid this, you can use either show show instead, which will apply the show function only to the numbers stored inside the Either, so
> putStrLn . either show show $ calc ...
should give you what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With