Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wishlist.



On July 3, 2015 11:38:26 PM CDT, Ori Bernstein <ori@xxxxxxxxxxxxxx> wrote:
>On Fri, 3 Jul 2015 14:45:04 -0500, Ryan Gonzalez <rymg19@xxxxxxxxx>
>wrote:
>
>> Interesting portion:
>> 
>> 
>> http://blog.burntsushi.net/rust-error-handling/
>> Informal intro to Rust-style error handling via monads, although the
>site
>> avoids the word "monad" to avoid invoking excess fear.
>
>http://git.eigenstate.org/ori/mc.git/tree/libstd/option.myr
>http://git.eigenstate.org/ori/mc.git/tree/libstd/result.myr
>http://git.eigenstate.org/ori/mc.git/tree/libstd/try.myr
>
>The thing is that so far, it still feels clunky. What Rust does to help
>is putting in macros. I really don't want arbitrary macros, but at the
>same
>time, the kind of stuff that Haskell desugars to goes against the
>"spirit"
>of the language:
>
>>
>http://felix-lang.org/$/usr/local/lib/felix/felix-latest/share/lib/std/datatype/option.flx
>> Felix implementation version of the above
>
>Hm. They seem to have a number of interesting utility functions, at
>least. I'd
>consider snarfing a few of those.
>
>> f n = do
>>   a <- someFunction
>>   a + n
>
>f n = 
>    someFunction >>= (\a -> a + n)

...except, that's invalid. The second function passed to >>= must return a monadic value. I think you meant:

someFunction >>= (\a -> return $ a+n)

or:

(n+) <$> someFunction

>
>Which is doable in Myrddin:
>
>    const f = {
>        -> std.bind(someFunction(), {
>            -> a + n
>        })
>    }
>
>Chaining further gets ugly, though:
>
>    const f = {
>        -> std.bind(std.bind(std.bind(someFunction(), {
>                    -> a + n
>                }), {b
>                -> b + n
>            }), {c
>            -> c + n
>        })
>    }
>
>I've considered adding a 'flip' operator, eg, $ which would clean up
>the syntax a little bit. Flip would basically chain two functions:
>
>    a $fn c
>
>would be equivalent to
>
>    fn(a, c)
>
>I might even have it allow extra arguments:
>
>    a $fn(c, d) b
>
>But even then it isn't quite as generic as Haskell, looks kind of ugly,
>and
>would make performance suck without lots of unimplemented
>optimizations.

Well, Myrddin already has traits. You could do something like Haskell's 'do' syntax. The person would put something like this:

try: std.option
 a()
 b()
error e
 ...
;;

The 'try' is just syntactic sugar. It takes a type T that implements some trait ('error'?) and a sequence of statements and does this:

For every statement that returns an item X of type T:
 If calling std.is_error or something like that on X returns true:
  Jump to the 'error' block, giving it X.

>
>> On Fri, Jul 3, 2015 at 2:11 PM, Ori Bernstein <ori@xxxxxxxxxxxxxx>
>wrote:
>> 
>> > Wrote up a wishlist. Pretty much, it's a list of things that I'd
>like to
>> > work
>> > on at some point. Unless someone else gets to them first, of
>course.
>> >
>> > http://eigenstate.org/myrddin/wishlist
>> >
>> > --
>> >     Ori Bernstein
>> >
>> >
>> 
>> 
>> -- 
>> Ryan
>> [ERROR]: Your autotools build scripts are 200 lines longer than your
>> program. Something’s wrong.
>> http://kirbyfan64.github.io/

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Follow-Ups:
Re: Error Handling [Was: WishlisOri Bernstein <ori@xxxxxxxxxxxxxx>
References:
Wishlist.Ori Bernstein <ori@xxxxxxxxxxxxxx>
Re: Wishlist.Ryan Gonzalez <rymg19@xxxxxxxxx>
Re: Wishlist.Ori Bernstein <ori@xxxxxxxxxxxxxx>