This document provides a guide for Haskell practice 2. It contains:
1. Definitions for several functions including successor, predecessor, max, min, double, sum doubles, distance between points, exists in list, maytra, maylin, and glotin.
2. A problem set asking to write functions for:
a) Summing the even elements of a list
b) Checking if a list contains any odd elements
c) Inserting an element at the start of a list
d) And more list operations
3. Example lists l1 and l2 are provided for testing functions.
This document provides a guide for Haskell practice 2. It contains:
1. Definitions for several functions including successor, predecessor, max, min, double, sum doubles, distance between points, exists in list, maytra, maylin, and glotin.
2. A problem set asking to write functions for:
a) Summing the even elements of a list
b) Checking if a list contains any odd elements
c) Inserting an element at the start of a list
d) And more list operations
3. Example lists l1 and l2 are provided for testing functions.
This document provides a guide for Haskell practice 2. It contains:
1. Definitions for several functions including successor, predecessor, max, min, double, sum doubles, distance between points, exists in list, maytra, maylin, and glotin.
2. A problem set asking to write functions for:
a) Summing the even elements of a list
b) Checking if a list contains any odd elements
c) Inserting an element at the start of a list
d) And more list operations
3. Example lists l1 and l2 are provided for testing functions.
This document provides a guide for Haskell practice 2. It contains:
1. Definitions for several functions including successor, predecessor, max, min, double, sum doubles, distance between points, exists in list, maytra, maylin, and glotin.
2. A problem set asking to write functions for:
a) Summing the even elements of a list
b) Checking if a list contains any odd elements
c) Inserting an element at the start of a list
d) And more list operations
3. Example lists l1 and l2 are provided for testing functions.
I I. . E Es sc cr ri ib bi ir r y y p pr ro ob ba ar r l la as s s si ig gu ui ie en nt te es s f fu un nc ci io on ne es s: :
s su uc ce es so or r n n = = n n+ +1 1
a an nt te ec ce e n n = = n n- -1 1
m ma ax xi i a a b b | | a a> >b b = = a a | | o ot th he er rw wi is se e = = b b
m mi in ni i a a b b | | a a< <b b = = a a | | o ot th he er rw wi is se e = = b b
d do ob bl la am me e a a = = a a+ +a a
d do ob bl la an no os s a a b b = = d do ob bl la am me e a a + + d do ob bl la am me e b b
d do ob bl la am me e1 10 00 0 a a = = i if f a a< <1 10 00 0 t th he en n d do ob bl la am me e a a e el ls se e a a
d di is sx xy y x x1 1 y y1 1 x x2 2 y y2 2 = = s sq qr rt t ( (( (x x2 2- -x x1 1) )^ ^2 2 + + ( (y y2 2- -y y1 1) )^ ^2 2) )
m ma ay yd di is s x x1 1 y y1 1 x x2 2 y y2 2 x x3 3 y y3 3 = = i if f d da ab b > > d da ac c t th he en n ' 'C C' ' e el ls se e ' 'B B' ' w wh he er re e d da ab b = = d di is sx xy y x x1 1 y y1 1 x x2 2 y y2 2 d da ac c = = d di is sx xy y x x1 1 y y1 1 x x3 3 y y3 3
c ca ab be ez za a [ [] ] = = e er rr ro or r " "n no o s se e p pu ue ed de e. .. .. ." " c ca ab be ez za a ( (x x: :x xs s) ) = = x x
c cu ue er rp po o [ [] ] = = e er rr ro or r " "n no o s se e p pu ue ed de e. .. .. ." " c cu ue er rp po o ( (x x: :x xs s) ) = = x xs s
s su um ma a1 1a al ll l [ [] ] = = [ [] ] s su um ma a1 1a al ll l ( (x x: :x xs s) ) = = ( (( (x x+ +1 1) ): : s su um ma a1 1a al ll l x xs s) )
s su um ma a1 1a al ll l' ' l l1 1 = = m ma ap p ( (+ +1 1) ) l l1 1
e ex xi is st te e e e [ [] ] = = F Fa al ls se e e ex xi is st te e e e ( (x x: :x xs s) ) = = i if f e e= == =x x t th he en n T Tr ru ue e e el ls se e e ex xi is st te e e e x xs s
e ex xi is st te e' ' e e l l = = f fo ol ld dr r ( (| || |) ) F Fa al ls se e ( (m ma ap p ( (= == =e e) ) l l) )
m ma ay yt tr ra a [ [] ] = = 0 0 UNIVERSIDAD AUTONOMA JUAN MISAEL SARACHO CURSO DE HASKELL INGENIERIA INFORMATICA
GUIA PRACTICA 2
m ma ay yt tr ra a l l = = i if f s su um ml l > > s su um mt t t th he en n s su um ml l e el ls se e s su um mt t w wh he er re e s su um ml l = = s su um m l l s su um mt t = = m ma ay yt tr ra a ( (t ta ai il l l l) )
m ma ay yl li in n [ [] ] = = 0 0 m ma ay yl li in n l l = = i if f m ma ay yt tr ra al l > > m ma ay yt tr ra at t t th he en n m ma ay yt tr ra al l e el ls se e m ma ay yt tr ra at t w wh he er re e m ma ay yt tr ra al l = = m ma ay yt tr ra a l l m ma ay yt tr ra at t = = m ma ay yl li in n ( (t ta ai il l l l) )
g gl lo ot ti in n [ [] ] = = 0 0 g gl lo ot ti in n l l = = i if f m ma ay yl li in nl l > > m ma ay yl li in nt t t th he en n m ma ay yl li in nl l e el ls se e m ma ay yl li in nt t w wh he er re e m ma ay yl li in nl l = = m ma ay yl li in n l l m ma ay yl li in nt t = = g gl lo ot ti in n ( (t ta ak ke e ( (( (l le en ng gt th h l l) )- -1 1) ) l l) )
I II I. . E Es sc cr ri ib bi ir r l la as s f fu un nc ci io on ne es s n ne ec ce es sa ar ri ia as s p pa ar ra a l lo os s s si ig gu ui ie en nt te es s p pr ro ob bl le em ma as s: : a a) ) D Da ad da a u un na a l li is st ta a l l s su um ma ar r t to od do os s s su us s e el le em me en nt to os s p pa ar re es s ( (v va al lo or re es s p pa ar re es s) ) b b) ) D Da ad da a u un na a l li is st ta a l l d de ev vo ol lv ve er r T Tr ru ue e s si i e ex xi is st te e a al lg g n n e el le em me en nt to o i im mp pa ar r, , c ca as so o c co on nt tr ra ar ri io o F Fa al ls se e c c) ) I In ns se er rt ta ar r u un n e el le em me en nt to o a al l p pr ri in nc ci ip pi io o d de e u un na a l li is st ta a l l d d) ) I In ns se er rt ta ar r u un n e el le em me en nt to o a al l f fi in na al l d de e u un na a l li is st ta a l l e e) ) I In ns se er rt ta ar r u un n e el le em me en nt to o e en n u un na a l li is st ta a o or rd de en na ad da a f f) ) E El li im mi in na ar r l lo os s e el le em me en nt to os s q qu ue e s se ea an n p pa ar re es s ( (l lo os s v va al lo or re es s n no o l la as s p po os si ic ci io on ne es s) ) g g) ) E El li im mi in na ar r l lo os s e el le em me en nt to os s e en n l la as s p po os si ic ci io on ne es s i im mp pa ar re es s h h) ) E El li im mi in na ar r t to od do os s l lo os s e el le em me en nt to os s d de e u un na a l li is st ta a l l q qu ue e s se ea an n i ig gu ua al le es s a a u un n e el le em me en nt to o d da ad do o i i) ) E El li im mi in na ar r e el l e el le em me en nt to o e en n l la a p po os si ic ci i n n p p d de e u un na a l li is st ta a l l j j) ) D Da ad da a u un na a l li is st ta a l l c cr re ea ar r u un na a l li is st ta a c co on n t to od do os s l lo os s e el le em me en nt to os s p po os si it ti iv vo os s m ma ay yo or re es s a a c ce er ro o