Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| teaching:cc4101:tareas:2015-1:tarea3 [2015/05/20 15:37] – gsoto | teaching:cc4101:tareas:2015-1:tarea3 [2015/07/24 14:17] (current) – gsoto | ||
|---|---|---|---|
| Line 18: | Line 18: | ||
| </ | </ | ||
| - | Cada constructor genera estructuras del tipo '' | + | Cada constructor genera estructuras del tipo '' |
| <code scheme> | <code scheme> | ||
| Line 55: | Line 55: | ||
| {match b | {match b | ||
| | | ||
| - | {even {f}}) | + | {not {f}}) |
| " | " | ||
| + | </ | ||
| + | |||
| + | De todas formas un identificador puede servir para hacer match de los casos restantes: | ||
| + | |||
| + | <code scheme> | ||
| + | (run ' | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | {t : bool} | ||
| + | {f : bool}} | ||
| + | {def weekday {d : day} : bool | ||
| + | | ||
| + | | ||
| + | {case {sunday} => {f}} | ||
| + | {case otherday => {t}}}}} | ||
| + | | ||
| + | > "(t) : bool" | ||
| </ | </ | ||
| Line 76: | Line 99: | ||
| | | ||
| {case {S n1} => {even n1 {not b}}}}}} | {case {S n1} => {even n1 {not b}}}}}} | ||
| - | {even {S {S {S {O}}}}} {t}}) | + | {even {S {S {S {O}}}} {t}}}) |
| > "(f) : bool" | > "(f) : bool" | ||
| + | </ | ||
| + | |||
| + | Las funciones se representan por el simbolo lambda: | ||
| + | <code scheme> | ||
| + | (run ' | ||
| + | {t : bool} | ||
| + | {f : bool}} | ||
| + | {fun {x : bool} x}) | ||
| + | > " | ||
| </ | </ | ||
| Line 83: | Line 115: | ||
| <code scheme> | <code scheme> | ||
| - | < | + | < |
| <def> ::= {deftype <id> {<id> : < | <def> ::= {deftype <id> {<id> : < | ||
| Line 94: | Line 126: | ||
| | {fun {<id> : < | | {fun {<id> : < | ||
| | {match < | | {match < | ||
| - | | {< | + | | {< |
| < | < | ||
| Line 118: | Line 150: | ||
| - '' | - '' | ||
| - '' | - '' | ||
| - | - '' | ||
| - '' | - '' | ||
| - '' | - '' | ||
| Line 124: | Line 155: | ||
| - '' | - '' | ||
| - '' | - '' | ||
| + | - '' | ||
| Nuevamente, el output de la función es un '' | Nuevamente, el output de la función es un '' | ||
| Line 134: | Line 166: | ||
| > " | > " | ||
| </ | </ | ||
| - | Los constructores tienen tipos. La ausencia de argumentos se representa por '' | + | Los constructores tienen tipos de función con '' |
| <code scheme> | <code scheme> | ||
| (typeof ' | (typeof ' | ||
| Line 141: | Line 173: | ||
| O}) | O}) | ||
| "() -> nat" | "() -> nat" | ||
| - | </ | ||
| - | El tipo de función va con '' | ||
| - | <code scheme> | ||
| - | (typeof ' | ||
| - | {O : nat} | ||
| - | {S : {nat -> nat}}} | ||
| - | S}) | ||
| - | > "nat -> nat" | ||
| </ | </ | ||
| <code scheme> | <code scheme> | ||
| Line 158: | Line 182: | ||
| {S : {nat -> nat}}} | {S : {nat -> nat}}} | ||
| {S {t}}}) | {S {t}}}) | ||
| - | "TYPE ERROR: | + | "TYPE ERROR: |
| </ | </ | ||
| Line 202: | Line 226: | ||
| - Si la función no es recursiva, termina | - Si la función no es recursiva, termina | ||
| - Si la función es recursiva entonces todas las llamadas recursivas deben reducir en al menos un argumento y este debe ser el mismo en todos los casos. | - Si la función es recursiva entonces todas las llamadas recursivas deben reducir en al menos un argumento y este debe ser el mismo en todos los casos. | ||
| - | - Se considera como argumento disminuido estructuralmente a un identificador extraído de un match. | + | - Se considera como argumento disminuido estructuralmente a un identificador extraído de un match, siempre y cuando el argumento de match sea directamente un identificador. |
| - Considere que para cualquier argumento de una llamada recursiva, si no es un identificador proveniente de un match, no puede saber si disminuye estructuralmente. | - Considere que para cualquier argumento de una llamada recursiva, si no es un identificador proveniente de un match, no puede saber si disminuye estructuralmente. | ||
| Line 209: | Line 233: | ||
| <code scheme> | <code scheme> | ||
| - | (terminate ' | + | (terminate '{{deftype bool |
| - | | + | {t : bool} |
| - | | + | {f : bool}} |
| + | {deftype nat | ||
| + | | ||
| + | | ||
| {def weird {n1 : nat} {n2 : nat} : bool | {def weird {n1 : nat} {n2 : nat} : bool | ||
| - | {match | + | {match |
| - | | + | |
| - | {case {S n3} => {match n1 | + | {case {S n3} => {match n1 |
| - | {{case {O} => {weird n3 {S n1}}} | + | {{case {O} => {weird n3 {S n1}}} |
| - | | + | |
| - | {O}) | + | {O}}) |
| > " | > " | ||
| </ | </ | ||
| Line 225: | Line 252: | ||
| <code scheme> | <code scheme> | ||
| - | (terminate ' | + | (terminate '{{deftype bool |
| - | | + | {t : bool} |
| - | | + | {f : bool}} |
| + | {deftype nat | ||
| + | | ||
| + | | ||
| {def weird {n1 : nat} {n2 : nat} : bool | {def weird {n1 : nat} {n2 : nat} : bool | ||
| - | {match | + | {match |
| - | | + | |
| - | {case {S n3} => {match n1 | + | {case {S n3} => {match n1 |
| - | {{case {O} => {weird n3 {S n1}}} | + | {{case {O} => {weird n3 {S n1}}} |
| - | | + | |
| - | {O}) | + | {O}}) |
| > " | > " | ||
| </ | </ | ||
| - | En el último caso, se debe detectar que la primera llamada recursiva '' | + | En el último caso, se debe detectar que la primera llamada recursiva '' |

