Skip to content

Instantly share code, notes, and snippets.

@kutyel
Created July 13, 2022 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kutyel/a3bad56054e1754b12a823a375cf8a8f to your computer and use it in GitHub Desktop.
Save kutyel/a3bad56054e1754b12a823a375cf8a8f to your computer and use it in GitHub Desktop.
Chapter 1 of Essential F# in Elm
module Main exposing (Customer(..), calculateTotal)
type Customer
= Eligible { id : String }
| Registered { id : String }
| Guest { id : String }
calculateTotal : Customer -> Double -> Double
calculateTotal customer spend =
let
discount =
case customer of
Eligible _ ->
if spend >= 100.0 then
spend * 0.1
else
0.0
_ ->
0.0
in
spend - discount
john =
Eligible { id = "John" }
assertJohn =
calculateTotal john 100.0 == 90.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment