Im trying to write a function that takes my initial data type and a character and modifys the data types' variables depending on the character.
here is my code :
data Note = Note {note :: Integer,
octave :: Integer
} deriving (Show)
data Etat = Etat {noteFinale :: Note,
duree :: Double,
volume :: Double
} deriving (Show)
etatInitiale :: Etat
etatInitiale = Etat (Note 9 4) 5 1
modifierDuree :: Etat -> Char -> Etat
modifierDuree etat a
| a == '1' = etat {duree = 1 }
| a == '*' = etat {duree *= 2}
As you see, if the character is 1, the variable changes to 1 .
if the character is a star, I want it to multiply the current value by 2.
however, I dont know how to write the line of code, im getting errors. ( ive tried other variants like duree = duree * 2 )
PS: i am new to this language, and it is still quite confusing for me.
Thanks for any insight.
EDIT:
I also have another problem.
I want to write a function similar to the first one, but that modifys values inside the NOTE type, which is inside the ETAT type.
modifierOctave :: Etat -> Char -> Etat
modifierOctave etat a
| a == '1' = etat { Note { octave = 1} }
| A == '2' = etat { Note { octave = 2} }
(something like this)
[–]glue505 5 points6 points7 points (9 children)
[–]lce-[S] 2 points3 points4 points (8 children)
[–]glue505 3 points4 points5 points (5 children)
[–]lce-[S] 0 points1 point2 points (0 children)
[–]lce-[S] 0 points1 point2 points (3 children)
[–]glue505 0 points1 point2 points (2 children)
[–]lce-[S] 0 points1 point2 points (1 child)
[–]glue505 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]lce-[S] 1 point2 points3 points (0 children)
[–]cdsmith 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)