haskell - Typeclasses 101: GHC too "eager" to derive instance? -


given following code:

class c   foo :: ->  f :: (c a) => -> f = id  p :: (c a) => (a -> a) -> -> p g = foo . g 

now, if try invoke p f, ghc complains:

> p f no instance (c a0) arising use of `p' in expression: p f in equation `it': = p f 

i find surprising, since f accepts "a" has instance of typeclass c. reason?

edit: know did not define instance c shouldn't "proper" response be:

p f :: (c a) => ->  

when put plain expression ghci, trying print it, so

> p f 

is approximately same having following in file

main :: io () main = print $ p f 

as pointed out, p f :: (c a) => -> a. in order print $ p f ghc needs evaluate p f. ghc cannot evaluate value type class context without choosing dictionary pass in. so, needs find c a instance a, doesn't exit. needs find show instance a -> a. inability find either of these results in 2 errors

no instance (show (a -> a)) arising use of `print' no instance (c a) arising use of `p' 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -