[Haskell-beginners] filtering on a datatype
Alexander Chen
alexander at chenjia.nl
Tue Jun 2 16:05:51 UTC 2020
Hi,
given this:
import Data.Time
data DatabaseItem = DbString String
| DbNumber Integer
| DbDate UTCTime
deriving (Eq, Ord, Show)
theDatabase :: [DatabaseItem]
theDatabase =
[ DbDate (UTCTime
(fromGregorian 1911 5 1)
(secondsToDiffTime 34250))
, DbNumber 9001
, DbString "Hello, world!"
, DbDate (UTCTime
(fromGregorian 1921 5 1)
(secondsToDiffTime 34123))
]
question from textbook is : write a function that filters for DbDate values and returns a list of the UTCTime values inside them.
my question could you give me an example of a working function, I don't get how i use the filter function on a data type in a list. Hence i am kinda stuck.
thanks in advance.
best,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200602/62953207/attachment.html>
More information about the Beginners
mailing list