Je veux mettre à jour mon modèle ainsi:Application Maybes Lorsque la mise à jour un modèle
updatedModel =
if model.firstChord && model.secondChord then
{ model | firstChord = {}, secondChord = {} }
else
model
le firstChord et secondChord les deux sont du type Chord:
type alias Chord =
{ root : Maybe Pitch
, third : Maybe Pitch
, fifth : Maybe Pitch
}
Le type de terrain ressemble à:
-- pitch
type alias Pitch = (PitchName, PitchLevel)
-- pitch name
type alias PitchName = String
-- pitch level
type alias PitchLevel = Int
Mon modèle initial a ces domaines:
{ firstChord =
{ root = ("C", 3)
, third = ("E", 3)
, fifth = ("G", 3)
}
, secondChord =
{ root = ("F", 3)
, third = ("A", 3)
, fifth = ("C", 4)
}
J'aime avoir des valeurs de hauteur optionnelles.
Comment puis-je mettre à jour mon modèle en lui donnant une valeur OU rien?
Merci.
Pourquoi ne pas 'type PitchName = A | B | C | ... | G'. Et 'type Pitch = Pitch PitchName PitchLevel'. Alors 'somePitch = Pitch G 3' – z5h
Si firstChord et secondChord sont de type Chord alors' firstChord = {} 'serait illégal car {} n'est pas de type Chord. – jpierson