[Haskell-cafe] Newclasses

Wvv vitea3v
Sat Oct 5 10:24:53 UTC 2013


Stijn van Drongelen wrote
> On Fri, Oct 4, 2013 at 10:31 PM, Wvv <

> vitea3v@

> > wrote:
>> About newclass and compose data, we can do next:
>>
>>    newclass Foo [a] => FooList a where {containerMainipulation=...}
>>
>>    newclass Foo (Set a) => FooSet a where {containerMainipulation=...}
>>
>>    newclass Foo (Sequence a) => FooSeq a where
>> {containerMainipulation=...}
>>
>> so now I can switch any container of my data, changing only name of
>> newclass:
>>
>>   instance FooList MyData where {dataMainipulation=...}
>>
> 
> You can already solve that in Haskell 98:
> 
>     class Foo2 f where { containerManipulation = ... }
>     instance Foo2 [] where { ... }
>     instance Foo2 Set where { ... }
>     instance Foo2 Sequence where { ... }
> 
>     class (Foo2 f) => Foo1 f a where { dataManipulation = ... }
> 
> Or even:
> 
>     class Foo' a where { dataManipulation' = ... }
>     dataManipulation = dataManipulation' yourDefaultContainerManipulation

Yes, I agree, use newclasses for composite data is an additional, secondary
feature. Haskell has huge infrastructure of data to use alternative ways
instead using newclasses this way.



Stijn van Drongelen wrote
> On Fri, Oct 4, 2013 at 10:31 PM, Wvv <

> vitea3v@

> > wrote:
> 
> Let's see how many lines of code this costs in Haskell 98:
> 
>     instance Monad MyMonad where { ... }
>     instance Functor MyMonad where
>         fmap = liftM
>     instance Applicative MyMonad where
>         pure = return
>         (<*>) = ap
> 
> Only three lines more, and they're readable.

I see, we are looking to the same situation from different angles. I try to
show you why I think my point of view is important.
2 situations: first is more practical, second is more philosophical.

(1)  we have several libraries with lenses and lens-looking like libraries.
Why is the main popularity going to Kmett's library?
My answer: easy connection: just add one line " makeLens MyRecord'' " and we
already could use all their abilities.
Why Kmett's library of JSON is so popular. Sure, it more quicker, but what
is the main reason?
My answer: easy connection.

Why Pipes, Streams, Conduit, .... are not as super-popular as they could be?
They have very powerful abilities.
You need time not only for studying how this library works, but also how to
switch your data to library functions.

If you need to work with ... RMonad or MonadDatabase or something like this,
do you always know how to switch your data on?

(2) Let I have a lamp and I wish to switch it on. So, I say, I want to have
a plug. But you argue: this isn't necessary: you take 3 wires, green one you
contact here, blue one contact here, and finally, brown one contact there!
Easy!

Ok, now I wish to connect computer with iPhone. You say: take 12 wires ,
pins-scheme, ....
But I want USB-30pin  cable.
Newclasses are those connectors-plugs and adapters.
Deriving are those plugs.
Generic instances and Data instances are those  plugs.

Newclasses are something like deriving, but much-much flexible and more
universal (sure, we can't replace deriving with newclasses).

If I have a Data which has an instance of Foo and I want to switch it to
class Bar, and I have 2 newclasses: Foo2Tmp and Tmp2Bar, I do the next:

   instance Foo2Tmp MyData 
   instance Tmp2Bar MyData

done!
or much simpler if I have Foo2Bar newclass:

  instance Foo2Bar MyData

I do not care  how easy or complex those instances I could write without
newclasses.
My aim is not to connect, but use abilities, which I take after connection.
And newclass is amazing tool for easy connection between classes.



--
View this message in context: http://haskell.1045720.n5.nabble.com/Newclasses-tp5737596p5737833.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.




More information about the Haskell-Cafe mailing list