Created
March 25, 2024 10:35
-
-
Save adinapoli/12b6353de6f90c4d81aa611a47875912 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeApplications #-} | |
module Main where | |
import Prelude | |
import Text.Read | |
import Control.Exception (try, evaluate, SomeException) | |
read' :: Read a => String -> a | |
read' = Prelude.read | |
read'' :: Read a => String -> a | |
read'' s = either error id (readEither s) | |
main :: IO () | |
main = do | |
print =<< try @SomeException (evaluate (read' @Int "foo")) | |
print =<< try @SomeException (evaluate (read'' @Int "foo")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment