ekmett/free

"No instance for (Comonad (Cofree Maybe)) ..."

Closed this issue · 3 comments

Hi! Big fan; maybe I'm doing this wrong but the following code produces an error (Mac OS X 10.10.2, GHC 7.10.1 installed via homebrew, free-4.12.1):

import Control.Comonad
import Control.Comonad.Cofree
import Data.Functor.Identity

type Stream = Cofree Maybe

nums :: Stream Int
nums = unfold (\x -> (x, Just (x+1))) 0

firstNum :: Int
firstNum = extract nums -- error!

The error message is this:

<interactive>:1:1:
    No instance for (Comonad (Cofree Identity))
      arising from a use of ‘extract’
    In the expression: extract nums

I don't have this issue on my Arch setup, but that's at home and perhaps not as up-to-date. I get a similar issue with Data.Stream.Future (extract (Last True) produces a similar error).

glguy commented

The code as written loads with free-4.12.1. Additionally the error message pasted doesn't match the code above it.

Closing this ticket as there is in fact an instance of Comonad (Cofree Maybe)

I appreciate you looking into it. Barring a clipboard fail on my part (was on a city bus, perhaps distracted) though that really was what I was getting. But it looks to be resolved anyway now. Thank you!

If I had to guess I'd suppose you likely had two versions of free installed. We see errors like this from time to time at ghci when you have two versions of a package installed, and something builds against one, but ghci loads the other.