Skip to content

Instantly share code, notes, and snippets.

@neerajsingh0101
Created July 13, 2017 22:10
Show Gist options
  • Save neerajsingh0101/83f26c0c32c310ab01fe9a27f5bc9e98 to your computer and use it in GitHub Desktop.
Save neerajsingh0101/83f26c0c32c310ab01fe9a27f5bc9e98 to your computer and use it in GitHub Desktop.
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 ]
@csakis
Copy link

csakis commented Dec 29, 2019

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

@SoshiHomma
Copy link

^ 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