serokell / universum

:milky_way: Prelude written in @Serokell
MIT License
176 stars 26 forks source link

Explain how to write Show instances #221

Closed neongreen closed 4 years ago

neongreen commented 4 years ago

A workaround I found: if you add import qualified Prelude to your module, suddenly you can write Show instances as usual.

neongreen commented 4 years ago

Look ma, no show:

> import Prelude (Show)
> show

<interactive>:2:1: error: Variable not in scope: show

Doesn't work:

> data Foo = Foo

> instance Show Foo where show Foo = Foo

<interactive>:3:25: error:
    ‘show’ is not a (visible) method of class ‘Show’

And now it does!

> import qualified Prelude
> instance Show Foo where show Foo = "Foo"

And show is still not in scope:

> show

<interactive>:8:1: error:
    • Variable not in scope: show
gromakovsky commented 4 years ago

Interesting, I thought it was somewhere in the docs, but apparently it never went beyond Slack discussions.

Since show doesn't come from Show anymore, you can't write Show instances easily.

Looks like a good place (in README) to write how one can do it not easily (but still it looks quite easy).

Btw, we've been doing import qualified Text.Show which looks a bit better because one can easier realize what this import is for.

neongreen commented 4 years ago

May you and your kin prosper for a thousand years

gromakovsky commented 4 years ago

@Martoon-00 did you close it by mistake?

neongreen commented 4 years ago

Oh

gromakovsky commented 4 years ago

Btw, we've been doing import qualified Text.Show which looks a bit better because one can easier realize what this import is for.

Another reason for it is that if you use base-noprelude or mixins to make Prelude refer to Universum (or your own custom prelude based on Universum), import qualified Prelude probably won't work. When we talk about custom preludes it sometimes might be the case that Prelude is not Prelude from base.

I guess I have spare 10 minutes to do this issue, a PR should come shortly.

gromakovsky commented 4 years ago

:nate: #228

Martoon-00 commented 4 years ago

@Martoon-00 did you close it by mistake?

Yep, sorry :/