Initiation au langage Caml les fonctions

Cours initiation au langage Caml les fonctions, tutoriel & guide de travaux pratiques en pdf.

Fonctions : motivation

En Java : fonction = objet qu’on peut executer = objet avec une methode que l’on peut executer. interface FunctionIntString { String eval(int x); }
En Caml : # fun x -> (string_of_int x);; – : int -> string = <fun>
X D. Monniaux — Initiation au langage Objective Caml 16
Fonctions : utilisation en Java
abstract class FunctionIntString { abstract String eval(int x);
String[] mapArray(int [] in) { String[] out = new String[in.length]; for(int i=0; i<in.length; i++) { out[i] = eval(in[i]); } return out; }
}

Fonctions : utilisation en Java 

class IntToStringSurround extends FunctionIntString { String prefix, postfix;
IntToStringSurround(String aPrefix, String aPostfix) { prefix = aPrefix; postfix = aPostfix; }
public String eval(int x) { return (prefix + x + postfix); }
X D. Monniaux — Initiation au langage Objective Caml 18

Fonctions : utilisation en Java vs Caml

public static void main(String[] args) { IntToStringSurround obj = new IntToStringSurround(« <« , « > »); String[] t = obj.mapArray(new int[] {1, 3, 5}); }
Caml :
Array.map string_of_int [1; 3; 5];

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *