Open Kesanov opened 7 years ago
Funy thing: the function flatMap
is actually a monadic bind and I have not realized it up until now (I was using it for three months in scala).
So I think {flatMap : ... , singleton | wrap : ... }
might be very good names for bind
and pure
, since it is immediately obvious what they do.
Amazing! Why the ...
s though?
So, I'm still very busy, but as soon as I have time I'll review and merge this (and see/comment your last proposal)!
Fun fact: did you know you can generate N-tuples
in a non-hardcoded way? Take the following term:
n =>
init = edit => var => tup =>
(edit tup var)
more = tup => edit => var =>
(tup tup => vars => (edit tup var vars))
(for 1 n init i => more x => x)
The IPFS hash of that term is zb2rha5eNNhRQ254tQed6QoDxfjtAgwoBcG9tgdfPV4bY7whV
. When applied to any integer N
, it returns the constructor for the N-tuple
. For example:
nTuple = zb2rha5eNNhRQ254tQed6QoDxfjtAgwoBcG9tgdfPV4bY7whV
(nTuple 5)
Is equivalent to your tuple5.moon
.
Why the ...s though?
Because list/monad.moon
should contain:
flatMap = ... --hash
wrap = ... --hash
this :
{ flatMap: (a -> List b) -> (List a) -> (List b)
, wrap : a -> (List a)
}
this =
{flatMap: flatMap, wrap: wrap} -- or maybe {flatMap: flatMap, applicative: applicative} ?
(Similar for monoid, applicative etc)
So, you used moon save file
and it didn't work?
I had old version of moon-tool and it did not work for some reason
Fun fact: did you know you can generate N-tuples in a non-hardcoded way?
That is really cool. Is it also possible to generate get index tuple
(e.g. (get 0 (tuple 3 "a" "b" "c")) == "a")
in a non-hardcoded way?
Though it is really hard to understand, how does the function actually work. Something like moon run step
(which would do only one beta reduction each time you hit enter) would be really helpful.
BTW I uploaded all the files to IPFS so it should work now.
Yep, it is actually possible to do much more. The #
operator fully replaces Scheme's hygienic macro system. For example, you can compile Haskell-like ADT declarations to their Scott/Church encodings. Something like:
#(data "List a = Cons a (List a) | Nil")
Reducing to
{
Cons: head => tail => Cons => Nil => (Cons head (tail Cons Nil))
Nil: Cons => Nil => Nil
}
Or, for example, you could compile a Pythonish syntax to equivalent Moon terms:
#(python "
def foo(a, b):
return a * 2 + b * 3
def bar(a):
return a * a * a
export foo, bar
")
Reducing to:
{
foo: a => b => (add (mul a 2) (mul b 3))
bar: a => (mul a (mul a a))
}
Things I definitely plan to do in a future.
Yes, it is hard to understand initially because it involves some variable hacking, but the gist is simple. Introduce some "holes" (edit points) in an arbitrary λ-term ,and replace them with anything you want. On this case, I basically place edit points on those places:
<HERE> a => b => c => tup => (<HERE> tup a b c)
Allowing me to replace tup
by tup v
(where v
is a new bound variable, placed on the first <HERE>
). Do that n
times and you have a n-tuple
.
Thanks for uploading on IPFS :)
I did not yet figure out, how to publish the files trough ipfs...
What do you think about the alternative definition of
Failure
: