Closed jeanbaptiste-brasselet closed 6 years ago
Thanks for opening this issue, @jeanbaptiste-brasselet.
I was wondering why the Semigroup Typeclass was redefined here and why not use directly Z.Semigroup.
In real code one should certainly use Z.Semigroup
rather than define it oneself, but I chose to define Semigroup in the readme to demonstrate the problem type classes solve, in several steps:
concat :: String -> String -> String
. Only works for strings.concat :: a -> a -> a
. Permits nonsensical operations such as concat (null) (null)
.concat :: Concatenable -> Concatenable -> Concatenable
. Permits concat ([]) ('')
.concat :: Semigroup a => a -> a -> a
. No shortcomings. :)So I tried and the example didn't work anymore.
Good catch. The example is out of date. At some point since it was written we defined concat
for objects, so concat ({}) ({})
is now valid. I'll open a pull request to correct the example.
I was looking at this example from the documentation
I was wondering why the Semigroup Typeclass was redefined here and why not use directly Z.Semigroup. So I tried and the example didn't work anymore. After some time I found this https://github.com/sanctuary-js/sanctuary-type-classes/blob/master/index.js#L933-L940
And because of this
Hum I am sure to understand what's going on here, maybe someone with more experience could explain it to me.