[Haskell-cafe] Why is my 'text' missing an instance?

amindfv at mailbox.org amindfv at mailbox.org
Wed Nov 18 03:45:45 UTC 2020


Aha - this was it, mystery solved!

I was thrown off the scent by "instance Binary Text" not showing up in the instance list when doing this in ghci:

    > :m + Data.Text
    > :m + Data.Binary
    > :i Text

Thank you!
Tom

On Tue, Nov 17, 2020 at 04:14:13PM -0800, Tikhon Jelvis wrote:
> Wild guess—could there be an inconsistency between the version of the
> binary package the text library was built against and the version you got
> the class from in your failing example?
> 
> I don't see how that would happen given your setup, but it's also the only
> way I can imagine seeing that particular error.
> 
> On Tue, Nov 17, 2020, 15:57 amindfv--- via Haskell-Cafe <
> haskell-cafe at haskell.org> wrote:
> 
> > tl;dr: I seem to have two versions of 'text' on my system, both of which
> > should have an instance for (Binary Text). However, one version seems to
> > claim not to have that instance.
> >
> >     $ cat test.hs
> >     import qualified Data.Text as T
> >     import qualified Data.Binary as B
> >
> >     main = print $ B.encode $ T.pack "hello"
> >
> >     $ /usr/local/bin/ghci --version
> >     The Glorious Glasgow Haskell Compilation System, version 8.10.2
> >
> >     $ /usr/local/bin/ghci test.hs
> >     GHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help
> >     [1 of 1] Compiling Main             ( test.hs, interpreted )
> >
> >     test.hs:4:16: error:
> >         • No instance for (B.Binary T.Text)
> >             arising from a use of ‘B.encode’
> >         • In the second argument of ‘($)’, namely
> >             ‘B.encode $ T.pack "hello"’
> >           In the expression: print $ B.encode $ T.pack "hello"
> >           In an equation for ‘main’: main = print $ B.encode $ T.pack
> > "hello"
> >       |
> >     4 | main = print $ B.encode $ T.pack "hello"
> >       |                ^^^^^^^^^^^^^^^^^^^^^^^^^
> >     Failed, no modules loaded.
> >
> >     $ /usr/local/bin/ghc-pkg list text
> >     /usr/local/lib/ghc-8.10.2/package.conf.d
> >         text-1.2.3.2
> >     /home/name/.ghc/x86_64-linux-8.10.2/package.conf.d
> >         text-1.2.4.1
> >
> >     $ ghc-pkg-8.10.2 list text
> >     [same result]
> >
> >     $ /usr/local/bin/ghci -package text-1.2.3.2 test.hs
> >     GHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help
> >     [1 of 1] Compiling Main             ( test.hs, interpreted )
> >     Ok, one module loaded.
> >
> >     $ /usr/local/bin/ghci -package text-1.2.4.1 test.hs
> >     GHCi, version 8.10.2: https://www.haskell.org/ghc/  :? for help
> >     [1 of 1] Compiling Main             ( test.hs, interpreted )
> >
> >     test.hs:4:16: error:
> >         • No instance for (B.Binary T.Text)
> >             arising from a use of ‘B.encode’
> >         • In the second argument of ‘($)’, namely
> >             ‘B.encode $ T.pack "hello"’
> >           In the expression: print $ B.encode $ T.pack "hello"
> >           In an equation for ‘main’: main = print $ B.encode $ T.pack
> > "hello"
> >       |
> >     4 | main = print $ B.encode $ T.pack "hello"
> >       |                ^^^^^^^^^^^^^^^^^^^^^^^^^
> >     Failed, no modules loaded.
> >
> > Both text-1.2.3.2 and text-1.2.4.1 have a Binary instance for Text. What's
> > going on?
> >
> > (After writing this out I rebuilt an unmodified clone of text-1.2.4.1 but
> > I see the same results.)
> >
> > Thanks,
> > Tom
> >
> > _______________________________________________
> > Haskell-Cafe mailing list
> > To (un)subscribe, modify options or view archives go to:
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> > Only members subscribed via the mailman list are allowed to post.


More information about the Haskell-Cafe mailing list