La maison

La maison

Moyen

Instructions

Récite la comptine « This is the House that Jack Built ».

[Le] fait de placer une proposition à l'intérieur d'une autre proposition s'appelle l'enchâssement. C'est par les processus de récursion et d'enchâssement que l'on peut prendre un nombre fini de formes (mots et propositions) et construire un nombre infini d'expressions. De plus, l'enchâssement permet aussi de construire une structure infiniment longue, en tout cas en théorie.

La comptine se lit comme suit :

This is the house that Jack built.

This is the malt
that lay in the house that Jack built.

This is the rat
that ate the malt
that lay in the house that Jack built.

This is the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

This is the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

This is the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

This is the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

This is the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

This is the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

This is the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

This is the farmer sowing his corn
that kept the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

This is the horse and the hound and the horn
that belonged to the farmer sowing his corn
that kept the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.

Indices

Cet exercice porte sur la réécriture de code, alors on te fournit une solution qui passe déjà les tests.

Le défi consiste à la réécrire jusqu'à ce que tu en sois fier, et à apprendre quelque chose au passage.

Si tu ne sais pas par où commencer, voici quelques idées :

  • Essaie de réduire les répétitions au minimum.
  • Essaie de rendre le code lisible.

Prends ton temps.

Ne change qu'une chose à la fois, et vérifie que ta solution passe toujours les tests.

Amuse-toi bien !

Modifie via GitHub Le lien s'ouvre dans une nouvelle fenêtre ou un nouvel onglet
Haskell Exercism

Prêt à commencer La maison ?

Inscris-toi sur Exercism pour apprendre et maîtriser Haskell avec 107 exercices, et un vrai mentorat humain, le tout gratuitement.