Why is my 'text' missing an instance?

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

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@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.

Actually that can happen if there are two versions of text built against
different versions of binary, but ghc (or cabal in old mode, which let ghc
do it) picked the wrong version of binary for the version of text it chose.
On Tue, Nov 17, 2020, 19:15 Tikhon Jelvis
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@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.
_______________________________________________ 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.

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@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.

On Tue, Nov 17, 2020 at 06:54:58PM -0500, amindfv--- via Haskell-Cafe 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.
$ /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’
Hard to say what's different on your system, but on a Fedora 31 system with GHC 8.10.2 and text-1.2.4.1, I'm unable to reproduce the symptoms you report. $ ghci -package text-1.2.4.1 GHCi, version 8.10.2: https://www.haskell.org/ghc/ :? for help Prelude> import qualified Data.Text as T Prelude T> import qualified Data.Binary as B Prelude T B> main = print $ B.encode $ T.pack "hello" Prelude T B> main "\NUL\NUL\NUL\NUL\NUL\NUL\NUL\ENQhello" The interface file for Text 1.2.4.1 has the expected instances: $ ghc-pkg list ~/.local/ghc-8.10/lib/ghc-8.10.2/lib/package.conf.d ... text-1.2.4.1 ... ~/.ghc/x86_64-linux-8.10.2/package.conf.d (no packages) $ ghc --show-iface ~/.local/ghc-8.10/lib/ghc-8.10.2/lib/x86_64-linux-ghc-8.10.2/text-1.2.4.1/Data/Text.hi | grep '^instance' instance [orphan] Data.Binary.Class.Binary [Data.Text.Internal.Text] instance [orphan] Data.Data.Data [Data.Text.Internal.Text] instance [orphan] GHC.Classes.Eq [Data.Text.Internal.Text] instance [orphan] GHC.Exts.IsList [Data.Text.Internal.Text] instance [orphan] Data.String.IsString [Data.Text.Internal.Text] instance [orphan] Language.Haskell.TH.Syntax.Lift [GHC.Types.LiftedRep, instance [orphan] GHC.Base.Monoid [Data.Text.Internal.Text] instance [orphan] Control.DeepSeq.NFData [Data.Text.Internal.Text] instance [orphan] GHC.Classes.Ord [Data.Text.Internal.Text] instance [orphan] Text.Printf.PrintfArg [Data.Text.Internal.Text] instance [orphan] GHC.Read.Read [Data.Text.Internal.Text] instance [orphan] GHC.Base.Semigroup [Data.Text.Internal.Text] -- Viktor.
participants (4)
-
amindfv@mailbox.org
-
Brandon Allbery
-
Tikhon Jelvis
-
Viktor Dukhovni