La casa

La casa

Intermedia

Instrucciones

Recita la canción infantil «This is the House that Jack Built».

El proceso de colocar una frase o cláusula dentro de otra frase o cláusula se llama incrustación. Es a través de los procesos de recursión e incrustación que podemos tomar un número finito de formas (palabras y frases) y construir un número infinito de expresiones. Además, la incrustación también nos permite construir una estructura infinitamente larga, en teoría al menos.

La canción infantil dice así:

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.

Pistas

Este ejercicio trata sobre la refactorización de código, así que te damos una solución que ya pasa los tests.

El reto es reescribirla hasta que te sientas orgulloso de ella y aprendas algo en el proceso.

Si no sabes por dónde empezar, aquí tienes algunas ideas:

  • Intenta reducir al mínimo la repetición.
  • Intenta que el código sea legible.

Tómate tu tiempo.

Cambia una cosa a la vez y verifica que tu solución siga pasando los tests.

¡Diviértete!

Editar en GitHub El enlace se abre en una ventana o una pestaña nuevas
Haskell Exercism

¿Todo listo para empezar La casa?

Regístrate en Exercism para aprender y dominar Haskell con 107 ejercicios y mentoría humana real, todo gratis.