Skip to content

Instantly share code, notes, and snippets.

@allansideas
Created July 6, 2017 15:52
Show Gist options
  • Save allansideas/60658d50f4f6b5ab9738c05f419324a8 to your computer and use it in GitHub Desktop.
Save allansideas/60658d50f4f6b5ab9738c05f419324a8 to your computer and use it in GitHub Desktop.
Trying to figure out why unions aren't working...
module Main exposing (..)
import Html exposing (Html, text, div, img)
import Html.Attributes exposing (src)
---- MODEL ----
type alias Model =
{}
init : ( Model, Cmd Msg )
init =
( {}, Cmd.none )
---- UPDATE ----
type Msg
= NoOp
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
( model, Cmd.none )
---- VIEW ----
type MyThing
= AString String
| AnInt Int
| ATuple ( String, Int )
unionFn : MyThing -> String
unionFn thing =
case thing of
AString s ->
"It was a string: " ++ s
AnInt i ->
"It was an int: " ++ toString i
ATuple ( s, i ) ->
"It was a string and an int: " ++ s ++ " and " ++ toString i
view : Model -> Html Msg
view model =
div []
[ text (unionFn "String") ]
---- PROGRAM ----
main : Program Never Model Msg
main =
Html.program
{ view = view
, init = init
, update = update
, subscriptions = always Sub.none
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment