|
Boost : |
Subject: Re: [boost] [Hana] Informal review request
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2015-03-08 12:59:55
Vicente J. Botet Escriba <vicente.botet <at> wanadoo.fr> writes:
>
> Le 07/03/15 21:00, Louis Dionne a écrit :
> > Vicente J. Botet Escriba <vicente.botet <at> wanadoo.fr> writes:
> >
> >> Le 07/03/15 17:38, Louis Dionne a écrit :
> >>> Vicente J. Botet Escriba <vicente.botet <at> wanadoo.fr> writes:
> >> [...]
> >>
> >> Do you have an equivalence in Haskell to your datatype/generalized type?
> > No, but shooting from the hip you could approximate them with type
> > classes.
>
> A type class that is instantiated with another type class?
Like I said, I don't know Haskell well enough to tell whether
there's a direct mapping between data types in Hana and something
else in Haskell. Is there an equivalent to Fusion/MPL tags in Haskell?
> [...]
>
> Doesе
¹ÌÑ¡
Ðå½Ô
É
Íͽ¥
Ñ¥¹ÁÉ¥¹¥Á
°ÑåÁ±
ÍÌ(ø¡½Ñ
¥¹äѡչѥ½¸
Ñ
ÑåÁ¤Ñ¼
ÑÑåÁ°Ñ¡
Ð¥ÌÕÍѼ(ø¥¹ÍÑ
¹Ñ¥
ÑÑ¡½Ñ¡ÈÑåÁ±
ÍÍÌü()$Ý
Ì©ÕÍÐÕÍ¥¹Ñ¡QÕÁ±ÑåÁ±
ÍÌ
Ì¡
¬Ñ¼É½ÕÀÑ¡)¥É¹ÐQÕÁ±8ÉÁÉ͹Ñ
Ñ¥½¹ÌÕ¹ÈÑ¡Í
µÕµÉ±±¸
¥¸°)$´¹½Ð!
ͱ°Ý¥é
É
¹Ñ¡Éµ¥¡Ð±
¸Ý
äѼ¼¥Ð¸(((øøøl¸¸¹t(øøø¥å½Ô¡
Ù
¸¡Ñɽ¹½ÕÌÑåÁ
ÌÁ
¥È½Èá
µÁ±°Ñ¡µ
Ñ¡µ
Ñ¥
°(øøøÑÉ
¹Í½É´Õ¹Ñ¥½¸Í¡½Õ±(øøø(øøøÑÉ
¹Í½É´èÁ
¥È¡P±T¤à¡P´øH¤à¡T´øL¤´øÁ
¥È¡H°L¤(øøø(øøø̬¬¡
̽Ùɱ½
չѥ½¹Ìݽ¸Ð¹Ñ¼Á
ÍÌÑݼչѥ½¹Ì°ÕÐ(øøø©ÕÍÐ
¸½Ùɱ½
չѥ½¸¸(øøQ¡
ÐÌ
¸¥¹ÑÉÍÑ¥¹Á½¥¹Ð½Ù¥Ü¸!½ÝÙÈ°Ý¥Ñ Ñ¡¥Ì
ÁÁɽ
°(øøå½Ô
¸ÐÍ
äÑB"2gVæ7F÷"âBç7FVB&V6öÖW2£ââ&gVæ7F÷"³%Òà£à£â&vBâgVæ7F÷"2öæÇöæRGR&ÖWFW"ââ6¶VÆÂ÷R6âæ÷B[ÙÜHÚÝ[[ÙHÝ[XÙZ]HÛÈ[Ý[ÛËYØ\\ÜÈÙHXÝ]ÙHÛÝ[ÝYHHÚ[ÛHÝ\ØYY[Ý[ÛZ\
HØ[HÙY[\È[[Ý[ÙHÙ[ÝÜ\È\Ý
HÙ\ËÙHYY[[X\Â[\]HÛ\ÜÈ\Ú[ÈZ\HZ\ÂÙYH[ÝË]YHÝÈ\ÙHH\H[ÝXYÙHZ\\È[^[\HXØ]\ÙH]ÝXÚÜÈ[ÜHÛÜÙ[HÈÚ]\[È[[H
Z\\ÈÝH[ÝÜ[[JK\OÚÝ[ÝHH[ÝÜZ]\[ÙÜH[XÛÛY\Î[ÙÜH\JKH
HOJH
OBO\JKB\ÝY[ÝH\ÙH\È\ØXÚ[ÝHØ[ÝØ^H]\H\ÂH[ÝÜ]\ÈÈHHQ[ÝÜÚXÚthe N-argument
> > equivalent to the BiFunctor. Furthermore, you have to provide
> > N different functions to be able to transform it. So for example,
> > when transforming a tuple(int, int, int), you would have to say
> >
> > transform(tuple(1, 2, 3),
> > [](int i) { return i + 1; },
> > [](int i) { return i + 1; },
> > [](int i) { return i + 1; }
> > )
>
> As pair<T,T>, and list<T> tuple<T,T,T> can be seen as an instance of a
> Functor. But not its heterogeneous variants.
Fine, but what about tuple<T, U, T>? Clearly, transform should
receive three different functions:
transform : tuple<T, U, T> x (T -> A) x (U -> B) x (T -> C)
->
tuple<A, B, C>
And¹ÝÍÑ¥±°¡
Ù̵չѽȡ½Èܽѡ
е
¹Ì¤¸)$Ñ¡¥¹¬$´ÍÑ
ÉÑ¥¹Ñ¼Õ¹ÉÍÑ
¹Ý¡É½ÕÈÙ¥ÝÌ¥ÙÉè()e½ÔÀ½¸ÑÉ她Ѽ͡Ñɽ¹½ÕÌ
ÑÍÑÉÕÑÕÉ̱¥)ÑÕÁ±Ì
ÌÁɽÕÐÑåÁÌ°Ý¡¥ Ñ¡ä
É
ÐÑ¡µ½ÍÐ
Í¥±Ù°¸()$±¥ÐÑ¡ÑåÁµÍåÍÑ´½¹±Ù°¡¥¡ÈÕÀ
¹ÍÑÕÁ±Ì
Ì)¥áµ±¹Ñ
ÉÉ
å̽½©ÑÌÝ¥Ñ Ñ¡Í
µÑåÁ¡¹É
±¥é)ÑåÁ¤¸Q¡¥Ì
ÁÁɽ
¡
Ìͽµ
Ù
¹Ñ
Ì°±¥¥¹
±Ñ¼±½½¬)
н©Ñ̽ѡQåÁ
ÑÑåÁ
̽©Ñ̽ѡÍ
µÑåÁ¸)Q¡½Í½©ÑÌ
±°¡
Ù½µµ½¸¥¹ÑÉ
°Ý¡¥ ½ÉÉÍÁ½¹ÌѼ)Ñ¡ñÑåÁ}ÑÉ
¥ÑÌø¸(((øøQ¡
Ð̹½Ð¡Ñɽ¹½ÕÌÁɽÉ
µµ¥¹ì¥ÐÌ©ÕÍÐ
¸ÅÕ¥Ù
±¹ÐÝ
ä½(øøÝɥѥ¹(øø(øøÈÄôÄ¡ÐĤ(øøÈÈôÈ¡ÐȤ(øø¸¸¸(øøɸô¸¡Ñ¸¤(øøâvW&RF¶&RFRVÆVÖVçG2öbGWÆRÂæBf¶&RFP£ââgVæ7Föç2ÖVBöâB'FRâÔgVæ7F÷"w2G&ç6f÷&Öà£ââvBvR7GVÆÇvçB0£âà£ââ#ÒbC£ââ#"ÒbC"£ââââà£ââ&âÒbFâ£âà£ââvW&Rf2FVfæVB0£âà£ââb¢çFW'6V7FöâöbFRFFGW2öbFRGWÆRw2VÆVÖVçG2£ââÓà£ââ6öÖR÷FW"GR£âvÒ7W&RFöær7V6¶æBöbG&ç6f÷&ÖFöç22W6VgVÂâ÷vWfW"FR[ÝÜÈX]\X[^H[\Ù[\Ë]\È[\ÜÙ[ÙH^XÝHHØ[YH[È\ÈÚ]\[ÈÚ]H\ÚÂØ]YÛÜK^Ù\][ÝH\XÙH\HHÙ[\[^Y\H[Ý\ÛÜË\ÈH[Ý[ÛÚÜÙHÛXZ[\ÈHÙ]Ù[ØXÝÈÚ]ÚXÚHØ[ÈY\H\HØXÝÈ[H\B]ÛÝÝ\Ü[HÙÜ[H\È[YÜYYÛÛÙ\ÂÚ[]\È]XÚÛÜÙ\È\ËÈ[ÝHYX[ÊÊÌMËÌÛÛÙ\ÏÈÛÝ[Ý\HÛ\ÜÙ\È[\OÂY\ËÊÊÈÛÛÙ\ËH\ÝYX[]ÊÊÈÛÛÙ\ÈÛÝ[[\Â]ÛÛÝZ[ÈÛ[Z[Y\ÈÙ\\ËÚ]Ý]][ÈÈ^Z\\\Ù[][ÛËBÝÈHXÝÈ]HZ]\K[X^XOOXZÙ\È][ÜHYXÝ[Â[\XÝÚ]]\ÙÙ[[Ý\ÈØX?
> > Let's try to implement a type _maybe<A>:
> >
> > template <typename A>
> > struct _maybe {
> > struct empty { };
> >
> > union { A a; empty e; } val;
> > bool is_nothing;
> >
> > constexpr _maybe() : val{empty{}}, is_nothing{true} { }
> > constexpr _maybe(A a) : val{a}, is_nothing{false} { }
> > };
> >
> > Now, let's try to implement, for example, the `maybe` function,
> > which has signature maybe :: B x (A -> B) x _maybe<A> -> B.
> > Remember that those A's and B's are actually generalized types,
> > not usual C++ types (we're working with heterogeneous stuff):
> >
> > template <typename Default, typename F, typename M>
> > constexpr auto maybe(Default def, F f, M m) {
> > ÉÑÕɸ´¹¥Í}¹½Ñ¡¥¹üè¡´¹Ù
°¹¤ì(øøô(øø(øøMµÌ±¥ÐüQ¡¥ÌݽÉÌè(øø(øøµ
å Ä°mt¡¥¹Ð¤¤ìÉÑÕɸ¤¬Äìô°}µ
åñ¥¹ÐùìÅô¤ì(øø(øø ÕÐÑ¡¥Ì½Ì¹½Ð°Ù¸Ñ¡½Õ ÍÑèéÑÕÁ±ðø
¹ÍÑèéÑÕÁ±ñ¥¹Ðø¡
Ù(øøÑ¡Í
µ¹É
±¥éÑåÁè(øø(øøµ
å (øøÍÑèéÑÕÁ±ðùíô°(øømt¡¥¹Ð¤¤ìÉÑÕɸÍÑèéµ
}ÑÕÁ±¡¤¤ìô°(øø}µ
åñ¥¹ÐùìÅô(øø¤ì(øø(øø%Ð
¥±ÌÝ¥Ñ (øø(øøÉɽÈ襹½µÁ
Ñ¥±½ÁÉ
¹ÑåÁÌ ÑÕÁ±ð¡¹¼
ÉÕµ¹Ð¤ø
¹ÑÕÁ±ñ¥¹Ðø¤(øøÉÑÕɸ´¹¥Í}¹½Ñ¡¥¹üè¡´¹Ù
°¹¤ì(øøxùùøùùùùùùùùùø(ø(øQ¡¥Ì͵̹½Éµ
°Ñ¼µ¸()%Ð}¥Í|¹½Éµ
°°ÕÐ¥Ð̹½ÐÕÍÕ°¥¸½¹Ñáн
±¥¹Ý¥Ñ )¡Ñɽ¹½ÕÌÙ
±ÕÌ°
ÕÍå½Ô
¸ÐÉÑÕɸ½©ÑÌbFffW&Vç@§GW2g&öÒFBgVæ7FöââvBvRæVVB2Fò7F÷&RFRæf÷&ÖFöà§&WV&VBFòÖ¶RFB'&æ6âFRÖ&Rw2GRÂæBFVâvR6âÝ[^\ÜÚ[Û[ÚYHH[Ý[ÛY]Ø\ËÙHÛÝ[\ÙHÛÛÏK\×ÛÝ[ÏÈ\ÙHÝ\ØY[ÂÈXÚÈÚXÚ[ÚÙIÜH^XÝ][È[ÝXYÙÚ[È]][[YKZÙHÙHÈYÚÝË\È\È^Z[Y[HÙXÝ[ÛÛH[Z]][ÛÈÙÛÛÝ^Ì×KÙ\È]YX[È][Ý\]H\\ÈX^XH[Z]\\H\ØXHÛH\ÈY]K\ÙÜ[[Z[ÈÛÛÏÈHÛÝÙYHÚ\HÛÝ[H\ÙH[H][][YK[ÝIÜHYÚ^H\H[ÜÝH\Ù[\ÜÈ][[YK\ÝZÙHÛÜÝÜ[Û[[ÛÜÝ\X[\HÛÛ\][H\Ù[\ÜÈ]ÛÛ\[K][YK] ÜÈ^XÝHHÚ[È[H\ÈHÛY]\ÙÜ[[Z[×ÈX\K][Ý[ÈÛHX^XIÜÈØÝ[Y[][ÛÌNËBÝÙ]\\H\È[[\Ü[\Ý[Ý[ÛÈXZÙH]ÙY[X^XH[::optional: just(x) and nothing do not share
the same type. Hence, whether a just or a nothing will be
returned from a function has to be known at compile-time for
the return type to be computable at compile-time. This makes
Maybe well suited for static metaprogramming tasks but very
poor for anything dynamic.
> >
> >> [...]
> >>
> >> My point was more on how the library is checking the fist argument of
> >> Transform is a Functor and that the second argument is a "function" from
> >> the Functor's underlying type T to another type U.
> >>
> >> transform : Functor<T> x (T -> U) -> Functor(U)
> >>
> >> If the implementation declares transform as
> >>
> >> auto transform = [] (auto F, auto Fun)
> >>
> >> Couldn't the the library c¬Ñ¡
ÐÑ¡
ÉÕµ¹ÑÌÁ
ÍÍ¥¸
¹Õ¸(øøøÉÍÁÐÑ¡ÉÅեɵ¹ÑÌü(øøeÌ°ÕÐÑ¡
ÐݽձÉÅÕ¥ÉÕ¹ÍÑ
Ñ¥¹Ñ¡
ХХÌչѥ½¸(øøɽ´
ÑÑåÁPѼ
ÑÑåÁT°Ý¡¥ ¥Ì¥µÁÉ
Ñ¥
°¸%¸Á
ÉÑ¥Õ±
È(øø¥Ðµ
¹ÌÑ¡
ÐÑ¡¥Ìè(øø(øøÑÉ
¹Í½É´¡µ
}ÑÕÁ± İȰ̤°mt¡¥¹Ð¤¤ì(øøÉÑÕɸ¤¬Äì(øøô¤ì(øø(øøݽձ¹½Ðݽɬ¸%¹ÍÑ
½¹Ý½Õ±¹Ñ¼ÝÉ¥Ñ(øø(øøÑÉ
¹Í½É´¡µ
}ÑÕÁ± İȰ̤°¡
¹èéչѥ½¸ñ¥¹Ð¡¥¹Ð¤ø¡mt¡¥¹Ð¤¤ì(øøÉÑÕɸ¤¬Äì(øøô¤¤ì(øø(øøQ¡¸°Í
äå½Ô¡
Ù(øø(øøÑÉ
¹Í½É´¡µ
}ÑÕÁ± Ä°ÍÑèéÍÑÉ¥¹ì
ô°µå}±
ÍÍíô¤°(øø¡
¹èéչѥ½¸ðüüü üüü¤ø¡mt¡
ÕѼà¤ì(øø¸¸¸(øøô¤¤ì(øø(øøQ¡Ý
ä$ͥа¥ÐÌ©ÕÍй½Ð½¹Ù¹¥¹Ð¸½¥¹¥Ð÷VÆ@£ââFVfæFVÇf÷&6RW2Fò&RÖFVÖF6ÆÇ6÷'&V7BF÷Vvà£ââç7FVBÂÒFò6F6Ö÷7B&öw&ÖÖærW'&÷'2'6V6¶æp£ââFBb2gVæ7F÷"v62V7âb÷R6VæBâ&æFöУââgVæ7FöâÂFVâFR6ö×ÆW"vÆÂFVÆÂ÷RvW&R÷Rw&Rw&öærÀ£ââ'WBævöâwBà£âBHÙ]ÙÛÛ[[ÛÛÛÙ\ËÚXÚHHÈ[XÙH[HÛÛÙ\Ù]H\K\IÜÈHÛX[Ù[\[^][ÛZ\ÜÚ[ÈÛH^H[\Ý[[ÂÈYÙHHØ\]ÙY[ÛÛÙ\È[]H\\ËÚXÚH[È\BHØ[YH[H[ÙYHH[X\È]H[ÙHÙXÝ[ÛÛÙ[\[^Y]H\\ÈÌ×KH[È]HYYÈ[\Ý[]\HØÛÜHÙHX\K\È[HH\H[Ý[Û[ÙÜ[[Z[ÈX\HÜ[Ý\Ø^HÈÈ\HY]K\ÙÜ[[Z[ÈÜÝ]HØ[YH[YK]\ÝXÝYÈH[Z]][ÛÈÙH[\ÙXÝ[ÛÂZÙH\Ú[Û[H\ÈHX\H]YÙ\È]ÙY[[[YH[ÛÛ\[K][YK\ÚXØ[K[ÝHØ[X[\[]HÙ\]Y[Ù\ÈÚ]]\ÙÙ[[Ý\ÈØXÝÈ[[K]Z\[Ý\ÈÈHÛÝÛ]ÛÛ\[K][YKHÛÝÈre's a way to generalize this so that
it works with homogeneous sequences whose size is known at runtime
too, but I'm not tackling this right now.
Then, type-level computations come for free when you have
heterogeneous sequences, but we had just never saw it as
clearly as we do now.
Hana is not just a "pure functional" library that works at runtime.
It's a generalized Boost.Fusion which happens to use concepts from
the functional paradigm because it's convenient.
Regards,
Louis
[1]: https://github.com/ldionne/hana-thesis
[2]: http://ldionne.github.io/hana/structboost_1_1hana_1_1_maybe.html
[3]: http://ldionne.github.io/hana/index.html#tutorial-hetero
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk