In his job adicionarMedicamento :: Medicamento -> Medicamentos -> Medicamentos
on the line adicionarMedicamento (a,b) [] = Medicamentos++[(a,b)]
you refers to the second function parameter, initially, as []
, however, following the addition of the medicinal product (a,b)
received the list of Medicines, you refers to the second function parameter, as Medicamentos
and this causes the error:
Data constructor not in scope: Medicamentos :: [(Nome, Quantidade)]
|
12 | adicionarMedicamento (a,b) [] = Medicamentos++[(a,b)]
| ^^^^^^^^^^^^
For the compiler knows the second function parameter as []
, to fix use the same parameter name as initially set.
Reading your code, I understand that you want to add a medicine to the list of medicines if that medicine is not on the list. However, if the medicine is already on the list, you want to increase the amount of the medicine. If based on this, I propose the following code:
type Nome = String
type Quantidade = Int
type HorarioProximo = Int
type HoraAtual = Int
type Horario = [Int]
type Medicamento = (Nome,Quantidade)
type Medicamentos = [Medicamento]
type Prescricao = (Nome,Horario,HorarioProximo)
type PlanoMedicamento = [Prescricao]
adicionarMedicamento :: Medicamento -> Medicamentos -> Medicamentos
adicionarMedicamento (a,b) c |elem (fst (a,b)) [fst c | c <- c] == False = c++[(a,b)]
|otherwise = aumentarDose (a,b) c
aumentarDose :: Medicamento -> Medicamentos -> Medicamentos
aumentarDose m ms |fst (head ms) == fst m = [(fst m, snd m + snd (head ms))]++tail ms
|otherwise = [head ms]++(aumentarDose m (tail ms))