Tipos De Datos. Muy Importante

Páginas: 6 (1355 palabras) Publicado: 16 de enero de 2013
{- tipos dados
foldr :: (a->b->b)->b->[a]->b
zip :: [a]->[b]->[(a,b)]
concat :: [[a]]->[a]
map :: (a->b)->[a]->[b]
(.) :: (b->c)->(a->b)->(a->c)
-}



-- EJERCICIO 1

{-
f = foldr (&&)
g p = f True . map p

h::Eq a => a->[a]->Bool -- este es el tipo que inferirÃa para h
h = g . (/=)
-}


{-
Comenzamos con f:

Decoracion: f::c = (foldr::(a->b->b)->b->[a]->b(&&)::Bool->Bool->Bool)::c

Ecuaciones: (a->b->b)->b->[a]->b = (Bool->Bool->Bool)->c

Resolucion: a=Bool, b=Bool, c=Bool->[Bool]->Bool

Tipo de f::Bool->[Bool]->Bool

-----------------------------

Tipo para g:
Dec: (g::d p::e)::f = ((.)::(b->c)->(a->b)->(a->c)
(f::Bool->[Bool]->Bool True::Bool)::g
(map::(h->i)->[h]->[i] p::e)::j)::f
Ecs:
d=e->f
Bool->[Bool]->Bool=Bool->g
(h->i)->[h]->[i]=e->j
(b->c)->(a->b)->(a->c)=g->j->f

Res:
Descomposicion en 2,3 y 4:
d=e->f
(2) g=[Bool]->Bool
e=h->i
(4) j=[h]->[i]
(5) g=b->c
(6) j=a->b
f=a->c

Sust 6 en 4: a->b=[h]->[i]; Sust 2 en 5: [Bool]->Bool=b->c
y descomponiendo:
d=e->f
g=[Bool]->Boole=h->i
a=[h]
(5) b=[i]
(6) b=[Bool]
c=Bool
j=a->b
f=a->c

Sust 6 en 5 y descomponiendo:
d=e->f
g=[Bool]->Bool
e=h->i
a=[h]
i=Bool
b=[Bool]
c=Bool
j=a->b
f=a->c

Sust a, i, b y c
d=e->f
g=[Bool]->Bool
e=h->Bool
a=[h]
i=[Bool]
b=[Bool]
c=Bool
j=[h]->[Bool]
f=[h]->Bool

Sust e, f:d=(h->Bool)->[h]->Bool
g=[Bool]->Bool
e=h->Bool
a=[h]
i=Bool
b=[Bool]
c=Bool
j=[h]->[Bool]
f=[h]->Bool

Tipo de g::(h->Bool)->[h]->Bool
-------------------------

Tipo para h:
Dec: h::d = ((.)::(b->c)->(a->b)->(a->c) g::(h->Bool)->[h]->Bool (/=)::Eq e=>e->e->Bool)::d

Ecs: (b->c)->(a->b)->(a->c)=((h->Bool)->[h]->Bool) -> (e->e->Bool) -> dEq e

Res: Descomponiendo:
b->c = (h->Bool)->[h]->Bool
a->b = e->e->Bool
d = a->c
Eq e

Descomponiendo 1 y 2:
(1) b = h->Bool
c = [h]->Bool
e = a
(4) b = e->Bool
d = a->c
Eq e

Sustituyendo 1 en 4 y descomponiendo:
b = h->Bool
c = [h]->Bool
(3) e = a
(4) h = e
d = a->c
Eq e

Sustituyendo 3:
b = h->Bool
c =[h]->Bool
e = a
(4) h = a
d = a->c
Eq a

Sustituyendo 4:
b = a->Bool
c = [a]->Bool
e = a
h = a
d = a->c
Eq a

Sustituyendo 2:
b = a->Bool
c = [a]->Bool
e = a
h = a
d = a->[a]->Bool
Eq a

Tipo para h::Eq a => a->[a]->Bool
-}





-- EJERCICIO 2
{-
g x = concat . map x -- g' :: (a -> [b]) -> [a] -> [b]
h= g (\ y -> y ++ "\n") -- h' :: [[Char]] -> [Char]
-}

{-
Comenzamos con g:
(g::d x::e)::f = ((.)::(b->c)->(a->b)->(a->c)
concat::[[g]]->[g]
(map::(h->i)->[h]->[i] x::e)::j
)::f

Ecs:
d=e->f
(h->i)->[h]->[i] = e->j
(b->c)->(a->b)->(a->c)=([[g]]->[g])->j->f

Decomponiendo 2 y 3:
d=e->f
e=h->ij=[h]->[i]
(4) b->c=[[g]]->[g]
j=a->b
f=a->c

Descomponiendo 4:
d=e->f
e=h->i
(3) j=[h]->[i]
b=[[g]]
c=[g]
(6) j=a->b
f=a->c

Sust 3 en 6:
d=e->f
e=h->i
j=[h]->[i]
(4) b=[[g]]
c=[g]
a=[h]
(7) b=[i]
f=a->c

De 4 y 7 sale i=[g]:
d=e->f
e=h->i
j=[h]->[i]
b=[[g]]
c=[g]
(6) a=[h]
(7) i=[g]f=a->c

Sust 6 y 7:
d=e->f
(2) e=h->[g]
j=[h]->[[g]
b=[[g]]
c=[g]
a=[h]
i=[g]
(8) f=[h]->c

Sust 2 y 8:
d=(h->[g])->[h]->c
e=h->[g]
j=[h]->[[g]
b=[[g]]
(5) c=[g]
a=[h]
i=[g]
f=[h]->c

Sust 5:
d=(h->[g])->[h]->[g]
e=h->[g]
j=[h]->[[g]
b=[[g]]
c=[g]
a=[h]
i=[g]
f=[h]->c


Tipo para...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Datos importantes
  • Datos Importantes
  • Importancia De Los Datos
  • Datos Importantes
  • dato importante
  • Datos Importantes
  • datos importantes
  • datos y tipos de datos

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS