3 ms·
Use a sum type: data Datum = S String | D Double lst :: [Datum] lst = [S "a", D 3.14] In Python we'd have to write the logic to handle both cases
by freyrs3 12y ago
Use a sum type:
data Datum = S String | D Double
lst :: [Datum]
lst = [S "a", D 3.14]
In Python we'd have to write the logic to handle both cases and fail with an exception or do an instanceof check. In Haskell we'd do this by pattern matching on the sum type.
case (lst !! 42) of
S n -> -- handle string
D n -> -- handle number