How to implement Either_vt?

29 views
Skip to first unread message

Kiwamu Okabe

unread,
Feb 22, 2015, 6:13:14 AM2/22/15
to ats-lang-users, ats-lang-users
Hi all,

Haskell language has Either type that represents values with two possibilities:
a value of type Either a b is either Left a or Right b.

http://hackage.haskell.org/package/base-4.7.0.2/docs/Prelude.html#t:Either

How to implement Either_vt on ATS2?

Best regards,
--
Kiwamu Okabe at METASEPI DESIGN

Shea Levy

unread,
Feb 22, 2015, 8:13:47 AM2/22/15
to ats-lan...@googlegroups.com, ats-lang-users
Check out http://ats-lang.sourceforge.net/LIBRARY/prelude/SATS/DOCUGEN/HTML/option_vt.html for how option_vt is implemented, it is the dataviewtype equivalent of Haskell’s Maybe. either_vt would take two type parameters, and instead of Some and None it would have Left and Right constructors.

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAEvX6d%3DS49_RCX%2Bz-Ce3_qXXYR-89TxaQwRM%2BW0XnMb9Mc%3D6pQ%40mail.gmail.com.

gmhwxi

unread,
Feb 22, 2015, 9:54:53 AM2/22/15
to ats-lan...@googlegroups.com, ats-lan...@lists.sourceforge.net, kiw...@debian.or.jp
In ATS, there are either_p (por) and either_v (vor) for props and views, respectively.



datavtype
either_vt
(
  a1
:vt@ype+
, a2:vt@ype+
, bool (*left/right:true/false*)
) =
 
| inj_left(a1, a2, true) of a1
 
| inj_right(a1, a2, false) of a2

vtypedef
Either_vt(a1:vt@ype, a2:vt@ype) = [b:bool] either_vt(a1, a2, b)



Surprisingly, the need for either_vt is very rare in practice. So it is not included in ATS at this moment.

Kiwamu Okabe

unread,
Feb 22, 2015, 11:56:34 PM2/22/15
to ats-lang-users, ats-lang-users
Hi Hongwei,

On Sun, Feb 22, 2015 at 11:54 PM, gmhwxi <gmh...@gmail.com> wrote:
> datavtype
> either_vt
> (
> a1:vt@ype+
> , a2:vt@ype+
> , bool (*left/right:true/false*)
> ) =
> | inj_left(a1, a2, true) of a1
> | inj_right(a1, a2, false) of a2
>
> vtypedef
> Either_vt(a1:vt@ype, a2:vt@ype) = [b:bool] either_vt(a1, a2, b)

Thank's. It's useful for me.
Because sometimes I have wanted to return an errno or a result.
However,,,

> Surprisingly, the need for either_vt is very rare in practice. So it is not
> included in ATS at this moment.

I think I understand your option_v is better than the Either_vt.
It doesn't touch the malloc heap.

Thank's,

Kiwamu Okabe

unread,
Feb 22, 2015, 11:58:38 PM2/22/15
to ats-lang-users, ats-lang-users
Hi Hongwei,

On Mon, Feb 23, 2015 at 1:56 PM, Kiwamu Okabe <kiw...@debian.or.jp> wrote:
>> Surprisingly, the need for either_vt is very rare in practice. So it is not
>> included in ATS at this moment.
>
> I think I understand your option_v is better than the Either_vt.
> It doesn't touch the malloc heap.

I miss-understand it. It's not "option_v" and "opt".
Reply all
Reply to author
Forward
0 new messages