Created
July 13, 2017 22:10
-
-
Save neerajsingh0101/83f26c0c32c310ab01fe9a27f5bc9e98 to your computer and use it in GitHub Desktop.
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 (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
main = | |
Html.beginnerProgram { model = model, view = view, update = update } | |
type alias UserInfo = | |
{ name : String, age : Int } | |
type alias Coach = | |
{ name : String, age : Int, sports : String } | |
model = | |
UserInfo "" 0 | |
getUserAge : UserInfo -> Int | |
getUserAge record = | |
record.age | |
printAge = | |
let | |
sam = | |
UserInfo "Sam" 24 | |
charlie = | |
Coach "Charlie" 52 "Basketball" | |
in | |
sam.name ++ " is " ++ toString sam.age ++ " " ++ charlie.name ++ " is " ++ toString charlie.age | |
type Msg | |
= Noop | |
update : Msg -> UserInfo -> UserInfo | |
update msg model = | |
model | |
view : UserInfo -> Html Msg | |
view model = | |
div [] [ text printAge ] |
^ I agreed. Like I tried writing down the similar code on Elm examples playground, that code puts an error.
Here's my code I wrote with your example: https://gist.github.com/SoshiHomma/2b75dced243a95e8831ee4e01a29cc0c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example is incorrect. You don't even use the getUserAge function. And you're wrong, getUserAge does not work with Coach type, it only works with "sam" , since sam is UserInfo type