Buscar..


Argumentos de función

type Dog = Dog String

dogName1 dog =
    case dog of
      Dog name ->
         name

dogName2 (Dog name) ->
     name

dogName1 y dogName2 son equivalentes. Tenga en cuenta que esto solo funciona para los ADT que tienen un único constructor.

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"

Aquí deconstruimos un registro y también obtenemos una referencia al registro no construido.

Argumento deconstruido de tipo único

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
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow