instrucciones basicas

6
INSTRUCCIONES BÁSICAS INSTRUCCIONES BÁSICAS DE HASKELL

Upload: viany1359327

Post on 11-Apr-2015

201 views

Category:

Documents


6 download

DESCRIPTION

fernando y yandira

TRANSCRIPT

Page 1: INSTRUCCIONES BASICAS

INSTRUCCIONES BÁSICAS

INSTRUCCIONES BÁSICAS DE HASKELL

Page 2: INSTRUCCIONES BASICAS

Type: Type: Permite renombrar tipos (no crea nuevos tipos)

Data: Data: Se crean nuevos tipos de datos mediante el uso de constructores.

La forma de introducir nuevos tipos es a través de las INSTRUCCIONES:

INSTRUCCIONES BÁSICAS DE HASKELL

Page 3: INSTRUCCIONES BASICAS

La declaración type simplemente hace un renombramiento, pero no introduce nuevos tipos de datos.

Ejemplo: Transformar las coordenadas de un punto 2D.transPunto:: (Int ,Int) -> (Int,Int)transPunto (x,y) = ....

Se puede renombrar la tupla (Int,Int) con un solo identificador, por ejemplo: Coordenadas.

INSTRUCCIONES BÁSICAS DE HASKELL

Page 4: INSTRUCCIONES BASICAS

En Haskell

type Coordenadas = (Int, Int)

transPunto:: Coordenadas -> Coordenadas

transPunto (x, y) = (y,x)

INSTRUCCIONES BÁSICAS DE HASKELL

Page 5: INSTRUCCIONES BASICAS

La instrucción data permite crear nuevos tipos de datos.

Ejemplo:data PALO = Oros|Copas|Espadas|Bastosdata FIGURA = As|Dos|Tres|Cuatro|Cinco|

Seis|Siete|Sota|Caballo|Rey

Con estas instrucciones se define en Haskell un nuevo tipo de datos que identifica a los palos y figuras de la baraja española.

INSTRUCCIONES BÁSICAS DE HASKELL

Page 6: INSTRUCCIONES BASICAS

INSTRUCCIONES BÁSICAS DE HASKELL

GRACIAS