Recherche…


Arguments de fonction

type Dog = Dog String

dogName1 dog =
    case dog of
      Dog name ->
         name

dogName2 (Dog name) ->
     name

dogName1 et dogName2 sont équivalents. Notez que cela ne fonctionne que pour les ADT qui ont un seul constructeur.

type alias Pet =
   { name: String
   , weight: Float
   
   }

render : Pet -> String
render ({name, weight} as pet) =
    (findPetEmoji pet) ++ " " ++ name ++ " weighs " ++ (toString weight)

findPetEmoji : Pet -> String
findPetEmoji pet = 
    Debug.crash "Implementation TBD"

Ici, nous déconstruisons un enregistrement et obtenons également une référence à l'enregistrement non reconstruit.

Argument déconstruit de type unique

type ProjectIdType = ProjectId String

getProject : ProjectIdType -> Cmd Msg
getProject (ProjectId id) =
    Http.get <| "/projects/" ++ id


Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow