undefined type ?

2 views
Skip to first unread message

carliros

unread,
Jun 10, 2009, 10:01:50 PM6/10/09
to Comunidad Haskell San Simon
{-
Tengo este script para manejar un entorno de declaraciones, Enviroment
tiene Celdas (guarda TIpo Nombre Valor de una declaracion), y lo que
estoy intentanto hacer son funciones para la manipulacion del
enviroment.

newTipoCell::Cell, me crea un celda con tipo especifico y valores por
defecto.
chNameCell:: Cell -> Name -> Cell, cambia el nombre de la celda dada.
chNameValueCell :: Cell -> Name -> ??Int, String, Bool??, me deberia
cambiar el nombre y su valor de una celda dada. Aqui tengo un problema
al definir su tipo, tampoco me da hacer una Patern-Matching

Alguna idea para arreglar esto ?

Lo que he estado queriendo es escribir una funcion que cree las celdas
correspondientes de a cuerdo a los parametros que le envie. En este
caso value.
-}
module Main where

type Enviroment = [Cell]

data Cell = Cell CellType CellName CellValue deriving Show
data CellType = Entero | Boolean | ListaInt | Object deriving Show
data CellValue =
ValueEntero Int
| ValueBoolean Bool
| ValueListaInt [Int]
| ValueObject
deriving Show
type CellName = String

--create cell
newIntCell::Cell
newIntCell = Cell Entero "default" (ValueEntero 0)
newListCell = Cell ListaInt "default" (ValueBoolean False)
newBoolCell = Cell Boolean "default" (ValueListaInt [])
newObjCell = Cell Object "default" (ValueObject)

-- actualize data cell
chNameCell:: Cell -> Name -> Cell
chNameCell (Cell t n v) name = Cell t name v


--chNameValueCell :: Cell -> Name -> ???
chNameValueCell (Cell t n v) name value::Int = Cell t name value
chNameValueCell (Cell t n v) name value::String = Cell t name value

carlos gomez

unread,
Jun 10, 2009, 10:08:37 PM6/10/09
to Comunidad Haskell San Simon
{-

un correccion:

--chNameValueCell :: Cell -> Name -> ????
chNameValueCell (Cell t n v) name value::Int     = Cell t name ValueEntero value
chNameValueCell (Cell t n v) name value::Bool  = Cell t name ValueBoolean value
chNameValueCell (Cell t n v) name value::[Int]   = Cell t name ValueListaInt value
chNameValueCell (Cell t n v) name value          = Cell t name ValueObject

-}

2009/6/10 carliros <carli...@gmail.com>

Juan Jose Olivera

unread,
Jun 10, 2009, 10:31:59 PM6/10/09
to hskg...@googlegroups.com
Dejame ver si te entiendo, lo que quieres hacer es forzar que la ultima funcion verifique que el Valor a cambiar se de mismo tipo que el valor anterior?

saludos

JJ

PD: Creo que los :: no son validos en el lado izquierdo de las funciones solo en el derecho

carlos gomez

unread,
Jun 10, 2009, 10:42:05 PM6/10/09
to hskg...@googlegroups.com
aaaa, quiero crear una funcion chNameValueCel, que al enviarle una Celll name y value, cambie el name y value de Cell.



2009/6/10 Juan Jose Olivera <jota.j...@gmail.com>

Juan Jose Olivera

unread,
Jun 10, 2009, 10:49:14 PM6/10/09
to hskg...@googlegroups.com
Lo siguiente me funciona y creo que cumple lo que quieres hacer

chNameValueCell :: Cell -> CellName -> CellValue -> Cell
chNameValueCell2chNameValueCell (Cell t cn (ValueEntero v)) cn2 (ValueEntero v2) = Cell t cn2 (ValueEntero v2)
chNameValueCell2chNameValueCell (Cell t cn (ValueBoolean v)) cn2 (ValueBoolean v2) = Cell t cn2 (ValueBoolean v2)
chNameValueCell2chNameValueCell (Cell t cn (ValueListaInt v)) cn2 (ValueListaInt v2) = Cell t cn2 (ValueListaInt v2)
chNameValueCell2chNameValueCell (Cell t cn (ValueObject)) cn2 (ValueObject) = Cell t cn2 (ValueObject)
chNameValueCell2chNameValueCell (Cell t cn _) cn2 _ = error  "tipos no validos"


saludos

JJ

carlos gomez

unread,
Jun 10, 2009, 11:13:20 PM6/10/09
to hskg...@googlegroups.com
aaa, que buena idea.

solo que olvide decir que tenia que usar algo asi como los tipos primitivos (int, bool, string) y no CellValue,
para que, para no tener que definir varias funciones que me creen los CellValue.

La idea viene por saber si hay una funcion que me diga si lo que tengo es un Int, Bool .. algo asi como una clase Object de Java, y hacer una comparacion typeOf para encontrar de que tipo es ... y asi hacer los cambios.
Reply all
Reply to author
Forward
0 new messages