<div dir="ltr">On Fri, Oct 4, 2013 at 10:31 PM, Wvv <span dir="ltr"><<a href="mailto:vitea3v@rambler.ru" target="_blank">vitea3v@rambler.ru</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Newclasses are something like instances, but out of scope. In a baggage.<br>
</blockquote><div><br></div><div>So under the hood of GHC, newclasses would be partially filled in dictionaries.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
We already have too many classes: (...)<br>
<br>
We can't divide all classes to atimic ones.<br></blockquote><div><br></div><div>As you have seen, we can. As you also see, it is a little impractical.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Main purpose of newclasses is to make instances as minimal as possible. In<br>
many cases empty.<br>
<br>
About newclass and compose data, we can do next:<br>
<br>
newclass Foo [a] => FooList a where {containerMainipulation=...}<br>
<br>
newclass Foo (Set a) => FooSet a where {containerMainipulation=...}<br>
<br>
newclass Foo (Sequence a) => FooSeq a where {containerMainipulation=...}<br>
<br>
so now I can switch any container of my data, changing only name of<br>
newclass:<br>
<br>
instance FooList MyData where {dataMainipulation=...}<br></blockquote><div><br></div><div>You can already solve that in Haskell 98:</div><div><br></div><div> class Foo2 f where { containerManipulation = ... }</div><div>
instance Foo2 [] where { ... }</div><div> instance Foo2 Set where { ... }</div><div> instance Foo2 Sequence where { ... }</div><div><br></div><div> class (Foo2 f) => Foo1 f a where { dataManipulation = ... }</div>
<div><br></div><div>Or even:</div><div><br></div><div> class Foo' a where { dataManipulation' = ... }</div><div> dataManipulation = dataManipulation' yourDefaultContainerManipulation</div><div><br></div>
<div>Remember: the only special things about type classes is that they are types that can/must be implicit. You can (almost?) always replace them by explicit parameters.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Or let I have an MyArrow data. And I need some semigroupoid manipulations.<br>
I just write<br>
<br>
instance ArrSemigroupoid MyArrow --empty<br>
<br>
that's all, I plug-in, let's just use semigroupoids functions!<br>
<br>
Or I have MyMonad and I want some Functor, so I just plug-in:<br>
<br>
instance MFunctor MyMonad --empty<br>
<br>
that's all.<br>
I also need some Applicative! Easy:<br>
<br>
instance MApplicative MyMonad --empty again<br>
<br>
done!<br></blockquote><div><br></div><div>Let's see how many lines of code this costs in Haskell 98:</div><div><br></div><div> instance Monad MyMonad where { ... }</div><div> instance Functor MyMonad where</div>
<div> fmap = liftM</div><div> instance Applicative MyMonad where</div><div> pure = return</div><div> (<*>) = ap</div><div><br></div><div>Only three lines more, and they're readable.</div>
<div><br></div><div><div>I think newclasses are not solving the existing problems, as you're only removing three well-understood lines of code in the above example, while people have to look up what you mean by MFunctor and MApplicative.</div>
</div><div><br></div><div>I think default superclass instances are a much better idea, or alternatively, the ConstraintSynonymInstances I previously mentioned (but not both -- they'll probably bite each other).</div>
<div>
<br></div><div>-Stijn</div></div></div></div>