User defined operators
Advertisement
factorial = rec ( fun fct . fun n . if n == 0.0 then 1.0 else n * (fct (n + -1.0)) );A recursive function via Y combinator. Need to think of how to add letrec bindings. Looked it up in the simon peyton jones implementing functional languages book. seems straightforward enough.
------
Woohoo I got user defined operators. As I was going about implementing some infix operators I thought to myself that user defined operators is a staple of functional languages. I do not plan to have operator overloading so +, - , < ,>, & etc cannot be implemented. but you can still define your own infix operator by simply putting brackets around the function name. I cant figure how to drop the brackets without mucking up the parser.
So the following works:
% = fun a . fun b . a mod b;5 [%] 3; // 2(% 5 3) // or use it lisp style. :sThis works for all functions. so i can go:mix = fun a . fun b . a * b + a;2 [mix] 3 // 8Advertisement
Advertisement
Advertisement
Discussion