Create upwards compatible APIs
type Movie =
Movie
{ title : String
, rating : Int
, -- adding a field will destroy the function below
}
new : String -> Int -> Movie
new title rating =
Movie
{ title = title
, rating = clamp 1 5 rating
}type Movie =
Movie
{ title : String
, rating : Int
, director : Maybe String
}
fromTitle : String -> Movie -> Movie
fromTitle title =
Movie
{ title : title
, rating : 0
, director : Nothing
}
withRating : Int -> Movie -> Movie
withRating rating (Movie movie) =
{ movie | rating = clamp 1 5 rating }
withDirector : String -> Movie -> Movie
withDirector director (Movie movie) =
{ movie | director = director }Question
Answer
Further Reading
Last updated