-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Q's about theoretically not using lambdas in HVM programs #109
Comments
|
About (2 / type constructor application). I suppose that yes, the type constructor application itself should be really fast, but as this would then need to be pattern matched (which should theoretical be much slower than lambda application, where the next computation step is already clear and a simple substitution + possible duplication). Although I haven't looked at the implementation to confirm this. |
Right so I meant the case where you are using the trivial pattern match with 1 option, I think you are right it is proportional to size of pattern but I specifically am interested in if there is different base overhead, I think victor posted some “mana cost” pictures based on measuring the actual implementation overhead but I don’t understand exactly how to map them onto this quite yet also don’t have them on hand |
Perhaps provide some example codes on what precisely you're talking about? But yes, the mana cost should be a fairly good estimative of the actual time/cost to run a program. Notice that most rewrite rules take about the same time, and none is faster than beta-reduction. |
Are these compiled identically? |
This is the current mana table:
You can test it using Kindelia's block evaluator:
The result is:
That means your first main consumes 15 mana, because it performs a global function call, thus, it uses the In short, calling a global function costs Note that, while a single lambda application is cheaper than a single global function call, it is still cheaper to implement recursive algorithms using global functions, because they avoid copying the lambda body (which Y-Combinators would need to do), and they entirely avoid computing case-of expressions (because pattern-matching / dispatch is built-in on global functions). |
Out of curiosity, is HVM without lambdas Turing-complete? See the below example, which has a single lambda: // List Map function
(Map f Nil) = Nil
(Map f (Cons x xs)) = (Cons (f x) (Map f xs))
// List projectors
(Head (Cons x xs)) = x
(Tail (Cons x xs)) = xs
// The infinite list: 0, 1, 2, 3 ...
Nats = (Cons 0 (Map λx(+ x 1) Nats))
// Just a test (returns 2)
Main = (Head (Tail (Tail Nats))) It looks like we can't define (Succ x) = (+ x 1)
Nats = (Cons 0 (Map Succ Nats)) Is there any way to write this program without lambdas? |
You can write it as
Don't know if there's a generic rewriting rule to transform programs into lambda-less ones. |
I think that I can program anything using just type constructors (and pattern matching / destructuring) and not use lambdas or lambda application at all.
The text was updated successfully, but these errors were encountered: