Variant unconstructor?

8 views
Skip to first unread message

chrisichris

unread,
Feb 16, 2012, 10:38:13 AM2/16/12
to yeti-lang
There ist the Variant constructor (ExampleVariant is 'a ->
ExampleVariant 'a) which is useful however I think a
VariantUnconstructor is even more useful:

uncunstructExampleVariant v = case v of ExampleVariant va: Some va;
_ : none esac;

the unconstructor would be useful every time list for Variants are
scanned ie in the optional parameters list pattern, when handling
async scatter/gather pattern:

assuming that a function (tagu) would make a VariantUnconstructor from
a VariantConstructor this could be used like

> maybeTag defaultFn valueFn unconstructor ls =
(res = ls |> map unconstructor |> catSome;
if empty? res then defaultFn () else valueFn (head res));

use it

fooFn options =
opt1 = maybeTag \1 id (tagu TimeOut) options;
opt2 = maybeTag None Some (tagu Url) options;

or in async opertions:

>requireTag unconstructor ls =
(res = ls |> map unconstructor |> catSome;
if empty? res then failWith "No conateined" else (head res));

> gatherAsync [do res: res (Name "foo") done, do res: res (Age 1) done,...] do results:
answer = {name = requireTag Name', age = requireTag Age'
done;

I mean this all warks with the case/esac patternmatch, but it would be
handy to easily construct the unconstructor.

So my question is; maybe this could be added to the language, or the
'name' field of yeti.lang.TagCon could be made public so I can
implement "tagu" function myself.

Thx,
Christian



I'd like to ask for some comiler support ie Tag names ending with '
are VariantUnconstructors
>ExampleVariant'





Reply all
Reply to author
Forward
0 new messages