Hello, i’m having a trouble where I need to create a function that uses data types that I created and I can’t understand the error that ghci throws
Here is my code:
data Carrera = Matematica | Fisica | Computacion | Astronomia | Profesorado
type Ingreso = Int
data Funcion = Teorico | Practico
data Rol = Decanx
| Docente Funcion
| Estudiante Carrera Ingreso
cuantos_doc :: [Rol] -> Funcion -> Int
cuantos_doc [] c = 0
cuantos_doc (x:xs) c =case f of
Docente c -> 1 + cuantos_doc xs c
otherwise -> cuantos_doc xs c
where f = x c
And here is the error
Proyecto2.hs:25:33: error:
• Couldn’t match expected type ‘Funcion -> t’
with actual type ‘Rol’
• The function ‘x’ is applied to one argument,
but its type ‘Rol’ has none
In the expression: x c
In an equation for ‘f’: f = x c
• Relevant bindings include f :: t (bound at Proyecto2.hs:25:29)
|
25 | where f = x c
| ^^^
Failed, no modules loaded.
I also tried using “case x c of…” and got this error
Proyecto2.hs:22:29: error:
• Couldn’t match expected type ‘Funcion -> Rol’
with actual type ‘Rol’
• The function ‘x’ is applied to one argument,
but its type ‘Rol’ has none
In the expression: x c
In the expression:
case x c of
Docente c -> 1 + cuantos_doc xs c
otherwise -> cuantos_doc xs c
|
22 | cuantos_doc (x:xs) c = case x c of
| ^^^
Failed, no modules loaded.
Thanks in advance