3 ms·
In some languages you don't give field names, just types. You bind fields to names only when pattern matching. For example in Haskell: type Year = Int
by rbonvall 8y ago
In some languages you don't give field names, just types. You bind fields to names only when pattern matching. For example in Haskell:
type Year = Int
type Month = Int
type Day = Int
-- fields have no names, just types
data Date = Date Year Month Day
-- we bind fields to names only when necessary
next (Date y 12 31) = Date (y + 1) 1 1
next (Date y m d)
| d == daysOf m = Date y (m + 1) 1
| otherwise = Date y m (d + 1)
where daysOf = (!!) [0, 31, 28, 31, 30,
31, 30, 31, 31,
30, 31, 30, 31]
Is something like this what you mean?
- usrusr 8y agoThank you, good to know. Maybe those who don't know Haskell are doomed to reinvent isolated parts of it.
- Iceland_jack 8y ago( yes )