Skip to content

Instantly share code, notes, and snippets.

@adinapoli
Created March 25, 2024 10:35
Show Gist options
  • Save adinapoli/12b6353de6f90c4d81aa611a47875912 to your computer and use it in GitHub Desktop.
Save adinapoli/12b6353de6f90c4d81aa611a47875912 to your computer and use it in GitHub Desktop.
{-# 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