Created
July 6, 2017 15:52
-
-
Save allansideas/60658d50f4f6b5ab9738c05f419324a8 to your computer and use it in GitHub Desktop.
Trying to figure out why unions aren't working...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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