|
Boost : |
Subject: Re: [boost] [Hana] Informal review request
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2015-03-07 15:00:17
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:
>
> [...]
>
> I see much more you datatype as a tag.
That's exactly what they are. However, Fusion and MPL did not see
tags for what they are actually: a powerful way of lifting the
type system one level higher up to make representation differences
unimportant. Fusion and MPL only saw tags as part of their dispatching
system. I think it's mostly a philosophical difference at this point.
> 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. For example, the Tuple data type c±¥µÁ±µ¹Ñ
Ì((´´Q¡¥É¹Ð
ÑÕ
°ÉÁÉ͹Ñ
Ñ¥½¹Ì½ÈÑÕÁ±Ì(
ÑQÕÁ±ÀôQÕÁ±À(
ÑQÕÁ±ÄôQÕÁ±Ä(
ÑQÕÁ±ÈôQÕÁ±È(
ÑQÕÁ±ÌôQÕÁ±Ì(´´Ñ¸¸¸((´´Q¡QÕÁ±¹É
±¥éÑåÁÉÁÉ͹ѥ¹
±°Ñ¡½ÍÕåÌ(±
ÍÌQÕÁ±ÐÝ¡É(±¸èèдø%¹Ð((¥¹ÍÑ
¹QÕÁ±QÕÁ±ÀÝ¡É(±¸|ôÀ((¥¹ÍÑ
¹QÕÁ±¡QÕÁ±Ä¤Ý¡É(±¸|ôÄ((¥¹ÍÑ
¹QÕÁ±¡QÕÁ±È¤Ý¡É(±¸|ôÈ((¥¹ÍÑ
¹QÕÁ±¡QÕÁ±Ì¤Ý¡É(±¸|ôÌ(´´Ñ¸¸¸(()µ¥Ñѱä°Ñ¡
½Ù¥Ìµ¥ÍÍ¥¹Í½µÑ¡¥¹Õ¹
µ¹Ñ
°¥ÝÝ
¹ÐѼ)¥µÁ±µ¹Ð½Ñ¡Èչѥ½¹Ì±¥¡
°ÕÐÑ¡
ÐÉ
¡ÌÑ¡±¥µ¥Ð½)µä!
ͱ°µÔ¸$Ñ¡¥¹¬±½½¥¹
Ð!
ͱ°ÌÑåÁ
µ¥±¥ÌlÅtµ@§&÷fFRÖ÷&Rç6vBà £ââ²ââåУâà£ââF22&V6W6RF2çVæ6R2÷föÇVçF&ÇòÆVgB6FRâÖ÷&P£ââvVæW&ÆÇÂFRFW6vâ6ö6RÖFRv2FòÆVfR&ÖWG&0£ââFFGW2FòFRFö7VÖVçFFöâÆWfVÂöæÇÂ22Fö7VÖVçFV@£âââFR6V7Föâ&÷WBvVæW&ƦVBFFGW5³Òà£à£â6âVæFW'7FæBFB÷RvçBFòÆWBFR6öç7G&çB26öÖÖVçG2÷"XZÙH\ÙH\ÜÈ[ÜH^XÚ]\ÈH[XYBØZYÛ\È\Ý\[ÈH\Ý[ÜX[]Y]ËÚ]HXZÙB\ÈHY[Ù]ÙY[X][X]XØ[ÛÜXÝ\ÜÈ[\ØX[]BÙHX\KÚ[H[HÝY\ÈÝXÝ\\È]Ø]\ÙBH]ÜÈYÛÜÝ\ÛKHØ[\Ù\ÈÈHXHÈ\ÙHÜÙBÝXÝ\\È[H]ZXÚÈ[\HØ^H\ÈHYX[ÙZ[È[ÜBÙXÝ]HÚ[YYYÜ^[\KHÛÝ[ÝØXÝÂÛÛY[ÛHÜ][ÈÜÙ]YØÛÙWN]]È×ÜÝ[ÈH×J]]È
HÈÊÛÛ\ÈHÝÝ[È
ÈNÂ]]ÈÈH[NXZÙWÝ\JKXÈNÂ]]È\ÈH[N[ÙÜJË×ÜÝ[ÊNÂÚ[ÙHX[XÈÈÝÚ\HHÛÛ[[Û]H\H[HÚYÛ]\HÙ[ÙÜX\È
Ü Functor F)
> >
> > transform : F(T) x (T -> U) -> F(U)
> >
> > , the above should normally be ill-formed. However, the library
> > makes such usage possible because I kept in mind that we're
> > working in a "dirty" heterogeneously-typed context. Bottom line:
>
> I don't think heterogeneous types are dirty. We need just a different
> type of function (Overloaded) to transform them.
>
> if you have an heterogeneous type as pair for example, the mathematical
> transform function should
>
> transform : pair(T,U) x (T -> R) x (U -> S) -> pair(R, S)
>
> As C++ has overloaded functions we don't need to pass two functions, but
> just an overloaded function.
That's an interesting point of view. However, with this approach,
you can't say that Pa¥Ìչѽȸ%Ð¥¹ÍÑ
½µÌ) ¥Õ¹Ñ½ÈlÉt¸ÕÉѡɵ½É°±ÐÌÍ
äå½Ô¡
ÙÁ
¥È¡P°P¤¸)ÑÉ
¹Í½É´¥ÌÑ¡¸((ÑÉ
¹Í½É´èÁ
¥È¡P°P¤à¡P´øH¤à¡P´øL¤´øÁ
¥È¡H°L¤()ÑÉ
¹Í½É´Í¡½Õ±¡¹ÍÑ¥±°É¥ÙÑݼչѥ½¹Ì°É
ɱÍ̽)Ñ¡
ÐÑ¡
ÐݽձÁɽ٥ͥ¹±½Ùɱ½
չѥ½¸¸()1е¹½ÜÕÍÑÕÁ±¥¹ÍÑ
½Á
¥È
Ì
¸á
µÁ±
ÕÍ¥Ð)Íѥ̵½É±½Í±äѼݡ
С
ÁÁ¹Ì¥¸!
¹¡A
¥È¥Ì¹½ÐչѽÈ)¥¸!
¹¤¸ÑÉ
¹Í½É´Ñ¡¸½µÌè((ÑÉ
¹Í½É´èQÕÁ±¡PÄ°¸¸¸°Q¸¤à¡PÄ´øHĤุ¸à¡Q¸´øI¸¤(´øQÕÁ±¡HÄ°¸¸¸°I¸¤()¥ÉÍа¥å½ÔÕÍÑ¡¥Ì
ÁÁɽ
°å½Ô
¸ÐÍ
äÑ¡
ÐQÕÁ±¥Ì)չѽȸ%С
ÌѼ8µÕ¹Ñ½È°Ý¡¥ ¥ÌÑ¡8µ
ÉÕµ¹Ð)ÅÕ¥Ù
±¹ÐѼѡ ¥Õ¹Ñ½È¸ÕÉѡɵ½É°å½Ô¡
Ùò&÷fFP¤âFffW&VçBgVæ7Föç2Fò&R&ÆRFòG&ç6f÷&ÒBâ6òf÷"W×ÆRÀ§vVâG&ç6f÷&ÖærGWÆRçBÂçBÂçBÂ÷Rv÷VÆBfRFò6 ¢G&ç6f÷&ÒGWÆRÂ"Â2À¢µÒçB²&WGW&â²²ÒÀ¢µÒçB²&WGW&â²²ÒÀ¢µÒçB²&WGW&ⲲТ ¥FBw2æ÷B&WFW&övVæV÷W2"&öw&ÖÖæs²Bw2§W7BâWVfÆVçBvö`§w&FærÛÜË\ÈH[Ý[ÛÚÜÙHÛXZ[\ÈHÙ]Ù[ØXÝÈÚ]ÚXÚHØ[ÈY\H\HØXÝÈ[H\B]ÛÝÝ\Ü[HÙÜ[H\È[YÜYYÛÛÙ\ÂÚ[]\È]XÚÛÜÙ\È\ËH[Ú\HZ[[IÜÈÙ[\[^Y\\È\ÈX[H]ÙHYH\\ÈÙHØXÝÈ[[ÛÛÚY\ØXÝÈ\]ËYY\[\\\Ù[][ÛËH[ÛÈ[È]Ø[HÙY[\ÈH][ÝY[ÙHÙ]Ù[\\ÈHH\]Z][[ÙH[][ÛHY[ÛHY[H[Ù[^XÝHHØ[YHÛÛÙ\È[^XÝHHØ[YHØ^BÛÛÜ][KHX][X]XØ[[]\ÙHÙIÜHÛÜÚ[ÈÚ]\ÈÝÛHHÙ]È] ÜÈXÝX[HHÊÊÈØ]YÛÜHÚ\HØXÝÈ\H\\Â[[Ü\Û\È\H[Ý[. Hence, that "quotient" would have to
also take morphisms into account. But I'm reaching the end of my
math-fu now.
> [...]
>
> How the fact to have either<A,B> and maybe<A> makes it more dificult to
> interact with heterogeneous objects?
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 Éݽɥ¹Ý¥Ñ ¡Ñɽ¹½ÕÌÍÑÕ¤è((ѵÁ±
ÑñÑåÁ¹
µ
ձаÑåÁ¹
µ°ÑåÁ¹
µ4ø(½¹ÍÑáÁÈ
ÕѼµ
å¡
ձа°4´¤ì(ÉÑÕɸ´¹¥Í}¹½Ñ¡¥¹üè¡´¹Ù
°¹¤ì(ô()MµÌ±¥ÐüQ¡¥ÌݽÉÌè((µ
å Ä°mt¡¥¹Ð¤¤ìÉÑÕɸ¤¬Äìô°}µ
åñ¥¹ÐùìÅô¤ì() ÕÐÑ¡¥Ì½Ì¹½Ð°Ù¸Ñ¡½Õ ÍÑèéÑÕÁ±ðø
¹ÍÑèéÑÕÁ±ñ¥¹Ðø¡
Ù)Ñ¡Í
µ¹É
±¥éÑåÁè((µ
å (ÍÑèéÑÕÁ±ðùíô°(mt¡¥¹Ð¤¤ìÉÑÕɸÍÑèéµ
}ÑÕÁ±¡¤¤ìô°(}µ
åñ¥¹ÐùìÅô(¤ì()%Ð
¥±ÌÝ¥Ñ ()ÉɽÈ襹½µÁ
Ñ¥±½ÁÉ
¹ÑåÁÌ ÑÕÁ±ð¡¹¼
ÉÕµ¹Ð¤ø
¹ÑÕÁ±ñ¥¹Ðø¤(ÉÑÕɸ´¹¥Í}¹½Ñ¡¥¹üè¡´¹Ù
°¹¤ì(xùùøùùùùùùùùùø()´¹¥Í}¹½Ñ¡¥¹¥Ì¹½Ð½¹ÍÑ
¹ÐáÁÉÍÍ¥½¸¥¹Í¥Ñ¡Õ¹Ñ¥½¸¸)%¥ÐÝ
̰ݽÕW6R&ööÅóÆÒæ5öæ÷FæsæFòW6R÷fW&ÆöFæp§Fò6²v6'&æ6vRw&RWV7WFærç7FVBöbFöærB@§'VçFÖRÂƶRvRFò&vBæ÷râF22WÆæVBâFR6V7Föà¦öâFRÆÖFFöç2öb6öç7FW"³5Òà £âà£ââ²ââåУâà£ââæ÷F6RÖWF£§V÷FRà£âvöæFW"bFRÖWF£§G&ç6f÷&Ò6÷VÆFâwBF¶R6&RöbV÷FRà ¤bBF¶W26&RöbV÷FRÂFVâvRæVVBFòÇv272FV×ÆFW0§FòvW"÷&FW"Æv÷&F×2â&66ÆÇÂFBv÷VÆB&RƶR66WFæp¦ÖWFgVæ7Föç2ç7FVBöbÖWFgVæ7Föâ6Æ76W2âFRÕÂçFW&f6Rà¥FW&R&RvööB&V6öç2æ÷BFòFòFBà £â²ââåУà£â×öçBv2Ö÷&Röâ÷rFRÆ'&'26V6¶ærFRf7B&wVÖVçBöb[ÙÜH[ÝÜ
OJHO[ÝÜJBYH[\[Y[][ÛXÛ\\È[ÙÜH\Â]]È[ÙÜHH×H
]]È]]È[BÛÝ[ÝHHX\HÚXÚÈ]H\Ý[Y[È\ÜÙY[[[\ÜXÝH\]Z\[Y[ÏÂY\Ë]]ÛÝ[\]Z\H[Ý][È]]\ÈH[Ý[ÛÛH]H\HÈ]H\HKÚXÚ\È[\XÝXØ[[\XÝ[\]YX[È]\Î[ÙÜJXZÙWÝ\JKÊK×J[JHÂ]\H
ÈNÂJNÂÛÝ[ÝÛÜË[ÝXYÛHÛÝ[YYÈÜ]B[ÙÜJXZÙWÝ\JKÊK[N[Ý[Û[
[
O×J[JHÂ]\H
ÈNÂJJNÂ[Ø^H[ÝH]B[ÙÜJXZÙWÝ\JKÝÝ[ÞÈXÈK^WØÛ\ÜÞßJK[N[Ý[ÛÏÏÊÏÏÊO×J]]È {
...
}));
The way I see it, it's just not convenient. Doing it would
definitely force us to be mathematically correct though.
Instead, I aim to catch most programming errors by checking
that F is a Functor (which is easy). If you send in a random
function, then the compiler will tell you where you're wrong,
but Hana won't.
Regards,
Louis
[1]: http://goo.gl/fY8pcw
[2]: http://goo.gl/Iy4FKu
[3]: http://ldionne.github.io/hana/#tutorial-constexpr
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk