-
-
Save benzen/9bc097e478ea8e368d2c to your computer and use it in GitHub Desktop.
Exercices
This file contains 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
// # Exercice 1: | |
// Étant données les deux fonctions suivantes: | |
// f :: a -> [b] | |
var f = (a) => [ a * a ]; | |
// g :: a -> [b] | |
var g = (a) => [ a + 10 ]; | |
// Écris l'implémentation de la fonction `compose` définie ainsi: | |
// compose :: (a->[b]) -> (a->[b]) -> (a->[b]) | |
// p.e. | |
// var h = compose(f, g); | |
// h //=> (a) => [ (a+10) * (a+10) ] | |
// h(2) //=> [ 144 ] | |
var compose = (k1, k2) => { | |
return k1(k2(a)); | |
}; | |
// # Exercice 2: | |
// Étant données `f`, `g` et `compose`, écris la fonction `bind` définie ainsi: | |
// bind :: [a] -> (a -> [b]) -> [b] | |
// p.e. | |
// bind([1,2,3], compose(f,g)) //=> [121, 144, 169] | |
var bind = (list, k) => { | |
return _.flatten(list.map(k));// peut mieux faire, p.ex sans lodash | |
}; | |
// # Exercice 3: | |
// Vérifie que ceci est vrai: | |
// | |
// bind(bind([1,2,3], g), f) === [121, 144, 169] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment