[Haskell-cafe] Extension and parameterized classes
allbery.b at gmail.com
Thu Feb 14 16:50:08 UTC 2019
Yes, and a large part of this being that hiding stuff tends to come back
and bite you when you need the internals anyway at some point. This leads
to .Internals modules and such in the end, sometimes retrofitted when the
need is realized.
On Thu, Feb 14, 2019 at 8:15 AM Mikolaj Konarski <mikolaj at well-typed.com>
> > I am aware that the signature of fromBase states that for all 'b' of Base
> > an Extend of type 'a' must be able to be made.
> > Yet, in my case 'a' is a parameterized class 'BaseExpose x' and
> > since the type of Extend is provided (it is a constructor)
> > I think it is acceptable that 'BaseExpose b' is returned as type.
> I'm afraid I'm agreeing with the compiler here. When you instantiate this
> class Base a => Extend a where
> fromBase :: Base b => b -> a
> so that `a` is `BaseExpose x`, then you need to implement
> fromBase :: Base b => b -> BaseExpose x
> and your fromBase' has a less general type
> fromBase' :: Base x => x -> BaseExpose x
> and that's it. It's the same issue as when you try
> to typecheck `id :: a -> b`. If it type-checked, you could
> write (pure) crashing type-correct code.
> I don't have enough data, but I guess you don't need `fromBase`
> at all. if `a` is `Base`, then it's also `Extend`, as long as you
> implement any extra operations. You don't need to coerce it
> to `Extend` with `fromBase`.
> BTW, as opposed to object oriented programmers,
> I think most of us doesn't use the class system
> for encapsulation, but the module system instead
> (with all its limitations). If the module system is not enough
> for you and you are ready for the bleeding edge,
> the Backpack may have what you need. Having said that,
> I think we usually err on the side of exposing too much,
> with all the simplicity and testing ease benefits it provides,
> rather than on the side of hiding too much. The user of a library
> is free to encapsulate more strongly in his import lists
> or by defining an interface module. Only the user knows
> his use case.
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
brandon s allbery kf8nh
allbery.b at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe