Language | ||||||||
---|---|---|---|---|---|---|---|---|
Common Lisp | mapc | mapcar | find-if | remove-if-not | reduce | reduce :from-end t | some | every |
Scheme | for-each | map | find | filter | fold, fold-left | fold-right | any, exists | every, for-all |
Haskell | mapM_ | map | find | filter | foldl | foldr | any | all |
Caml Light | do_list | map | - | - | it_list | list_it | exists | for_all |
OCaml | iter | map | find | filter, find_all | fold_left | fold_right | exists | for_all |
F# | iter | map | find | filter | fold | foldBack | exists | forall |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax aif | |
(ir-macro-transformer | |
(lambda (form inject cmp) | |
(let ((it (inject 'it)) | |
(expr (car (cdr form))) | |
(then (car (cdr (cdr form)))) | |
(else (car (cdr (cdr (cdr form)))))) | |
`(let ((,it ,expr)) | |
(if ,it ,then ,else)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax %cut | |
(sc-macro-transformer | |
(lambda (form use-env) | |
(capture-syntactic-environment | |
(lambda (mac-env) | |
(let ((rargs (cadr form)) | |
(rbody (caddr form)) | |
(rest (cdddr form))) | |
(define (id=? x y) | |
(and (identifier? x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax cut | |
(sc-macro-transformer | |
(lambda (form use-env) | |
`(cut% () () ,@(cdr form))))) | |
(define-syntax cut% | |
(sc-macro-transformer | |
(lambda (form env) | |
(let ((slots (cadr form)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax sc-cut | |
(sc-macro-transformer | |
(lambda (form use-env) | |
(capture-syntactic-environment | |
(lambda (mac-env) | |
(define (id=? x y) | |
(and (identifier? x) | |
(identifier=? use-env x | |
mac-env y))) | |
(let loop ((rargs '()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/plugins/extraction/scheme.ml b/plugins/extraction/scheme.ml | |
index 7915bc8..ee2b3fb 100644 | |
--- a/plugins/extraction/scheme.ml | |
+++ b/plugins/extraction/scheme.ml | |
@@ -23,14 +23,15 @@ open Common | |
let keywords = | |
List.fold_right (fun s -> Idset.add (id_of_string s)) | |
[ "define"; "let"; "lambda"; "lambdas"; "match"; | |
- "apply"; "car"; "cdr"; | |
+ "apply"; "car"; "cdr"; "list"; "letrec"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% -*- mode: prolog -*- | |
% type inference rules in | |
% Danvy, O., and A. Filinski: "A Functional Abstraction of Typed Contexts", | |
% Technical Report 89/12, DIKU, University of Copenhagen (July 1989). | |
extend_env(Env, Var, Typ, [Var:Typ|Env]). | |
lookup_env([Var:Typ|_], Var, Typ). | |
lookup_env([_|Env], Var, Typ) :- lookup_env(Env, Var, Typ). | |
ty(_, X, A, A, int) :- integer(X). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Haskell-style Functor in Java | |
// See also: | |
// highj: http://code.google.com/p/highj/ | |
// Higher-kinded programming in OCaml: https://github.com/ocamllabs/higher | |
import java.util.Arrays; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* type application F[A] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* https://issues.scala-lang.org/browse/SI-5195 *) | |
let swap (a, b) = (b, a) | |
type (_, _) f = | |
MapF : ('a -> 'b) -> ('a, 'b) f | |
| Pipe : ('a, 'b) f * ('b, 'c) f -> ('a, 'c) f | |
| Flip : ('a * 'b, 'b * 'a) f | |
let pipe = function | |
| MapF f, Flip -> MapF (fun x -> swap (f x)) |