tssm / up-to-date-real-world-haskell

I'm trying to update the Real World Haskell book
Other
792 stars 47 forks source link

handle needs to specify type of exception #16

Closed mushishi78 closed 4 years ago

mushishi78 commented 5 years ago

I tried to run this as is and my compiler errored:

    • Ambiguous type variable ‘e0’ arising from a use of ‘handle’
      prevents the constraint ‘(GHC.Exception.Type.Exception
                                  e0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘e0’ should be.
      These potential instances exist:
        instance GHC.Exception.Type.Exception SomeException
          -- Defined in ‘GHC.Exception.Type’
        ...plus 9 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the expression: handle (\ _ -> return Nothing)
      In the expression:
        handle (\ _ -> return Nothing)
          $ bracket (openFile path ReadMode) hClose
              $ \ h
                  -> do size <- hFileSize h
                        return (Just size)
      In an equation for ‘getFileSize’:
          getFileSize path
            = handle (\ _ -> return Nothing)
                $ bracket (openFile path ReadMode) hClose
                    $ \ h
                        -> do size <- hFileSize h