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/28 13:46] – gsoto | teaching:cc4101:tareas:2015-1:tarea3 [2015/07/24 14:17] (current) – gsoto | ||
---|---|---|---|
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" | ||
</ | </ | ||
Line 103: | Line 126: | ||
| {fun {<id> : < | | {fun {<id> : < | ||
| {match < | | {match < | ||
- | | {< | + | | {< |
< | < | ||
Line 127: | Line 150: | ||
- '' | - '' | ||
- '' | - '' | ||
- | - '' | ||
- '' | - '' | ||
- '' | - '' | ||
Line 160: | Line 182: | ||
{S : {nat -> nat}}} | {S : {nat -> nat}}} | ||
{S {t}}}) | {S {t}}}) | ||
- | "TYPE ERROR: | + | "TYPE ERROR: |
</ | </ | ||
Line 204: | 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 211: | 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 227: | 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 '' |