Jonas
Jonas

Reputation: 128975

No instance found for Prelude.Functor

I am following "Purescript by Example" book, and is implementing the code in Chapter 5. But I get a compilation error that I don't understand.

I get compilation error on this line (the code compiles without this line):

showPicture = map showShape

The error is:

No instance found for Prelude.Functor _67

And the error explanation does not make it clear for me. Why do I get this error?

I have these dependencies installed in my bower file:

"dependencies": {
  "purescript-console": "^0.1.0"
  "purescript-foldable-traversable": "~0.4.0",
  "purescript-globals": "~0.2.0",
  "purescript-math": "~0.2.0"
}

Upvotes: 1

Views: 97

Answers (1)

Phil Freeman
Phil Freeman

Reputation: 4169

You need to add a type signature.

The map function implies that you are using a Functor (in this case Array). So the general type of your function is

showPicture :: forall f. (Functor f) => f Shape -> f String 

You probably meant the more specific type

showPicture :: Picture -> Array String 

However, psc does not yet infer constraints, so you need a type signature to guide it. Hopefully psc will infer constraints before the 1.0 release, but for now, this is the workaround.

Upvotes: 1

Related Questions