[Haskell-cafe] Typeclass Constraint Causing Typechecker to Fail

Bryan Richter b at chreekat.net
Tue Apr 19 23:59:30 UTC 2016


On Tue, Apr 19, 2016 at 04:24:26PM -0700, James M wrote:
> Below I have a contrived example. Please do not take this to be real
> world code.
> 
> f :: (Show a) => Int -> (Int -> a) -> Int -> IO a
> f i g x = do
>     print i
>     return $ g (x + i)
> 
> foo :: Bool -> IO (Either [Int] [String])
> foo b = do
>     let helper = f 2
>     if b then
>         Left  <$> sequence (fmap (helper negate) [0,1])
>     else
>         Right <$> sequence (fmap (helper show) [0,1])
> 
> The above will fail stating...
>
> <snip>
> 
> This seems to be a bug in the typechecker, and maybe it is a well
> known issue.
> 
> Can someone please confirm that this is a bug and whether or not it
> is known?

I believe you have discovered everyone's favorite Haskell feature:

https://wiki.haskell.org/Monomorphism_restriction
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160419/f5e76d1f/attachment.sig>


More information about the Haskell-Cafe mailing list