Skip to content

Instantly share code, notes, and snippets.

@greatBigDot
Last active June 2, 2019 03:28
Show Gist options
  • Select an option

  • Save greatBigDot/5fb2171f2f9968bc619178d6d1cac066 to your computer and use it in GitHub Desktop.

Select an option

Save greatBigDot/5fb2171f2f9968bc619178d6d1cac066 to your computer and use it in GitHub Desktop.
Inferred type is invalid
{-# LANGUAGE AllowAmbiguousTypes, MultiParamTypeClasses, NoMonomorphismRestriction #-}
module InvalidInference where
class Foo s t where
foo :: t
-- When commented, GHCi infers this type; when uncommented, it yields a type error:
-- bar :: Foo s t => t
bar = foo
{-
Here's the error in question:
InvalidInference.hs:10:7: error:
• Could not deduce (Foo s0 t) arising from a use of ‘foo’
from the context: Foo s t
bound by the type signature for:
bar :: forall s t. Foo s t => t
at InvalidInference.hs:9:1-19
The type variable ‘s0’ is ambiguous
Relevant bindings include bar :: t (bound at InvalidInference.hs:10:1)
• In the expression: foo
In an equation for ‘bar’: bar = foo
|
10 | bar = foo
| ^^^
Failed, no modules loaded.
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment