<div><div dir="auto">I can see why you’re a bit confused here, the question is poorly written. You can not use the Prelude filter function to do this, but you do need to write a function that filters and maps over the data to do this transformation (onlyDateTimes below is an example type signature for such a function).</div></div><div dir="auto"><br></div><div dir="auto">mapMaybe is the sort of function you may to use for this purpose.</div><div dir="auto"><br></div><div dir="auto">Here are some type signatures as a hint for one way to implement it:</div><div dir="auto"><br></div><div dir="auto">dbDateTime :: DatabaseItem -> Maybe UTCTime</div><div dir="auto"><br></div><div dir="auto">onlyDateTimes :: [DatabaseItem] -> [UTCTime]</div><div dir="auto"><br></div><div dir="auto">There are of course other ways to implement onlyDateTimes such as directly using pattern matching and recursion, or using foldr, concatMap, etc. I would go with whichever method you’ve learned from the textbook so far. </div><div dir="auto"><br></div><div dir="auto">-bob</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 2, 2020 at 09:06 Alexander Chen <<a href="mailto:alexander@chenjia.nl">alexander@chenjia.nl</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-family:Arial;font-size:13px"><div>Hi,</div><div><br></div><div>given this:</div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Courier New",monospace;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:#569cd6">import</span> <span style="color:#4ec9b0">Data.Time</span></div><br><div><span style="color:#569cd6">data</span> <span style="color:#569cd6">DatabaseItem</span> = DbString <span style="color:#569cd6">String</span></div><div>                  | DbNumber <span style="color:#569cd6">Integer</span></div><div>                  | DbDate   <span style="color:#569cd6">UTCTime</span></div><div>                  <span style="color:#569cd6">deriving</span>  (<span style="color:#569cd6">Eq</span>, <span style="color:#569cd6">Ord</span>, <span style="color:#569cd6">Show</span>)</div><br><div><span style="color:#dcdcaa">theDatabase</span> :: [<span style="color:#569cd6">DatabaseItem</span>]</div><div>theDatabase =</div><div>    [ DbDate (UTCTime</div><div>             (fromGregorian <span style="color:#b5cea8">1911</span> <span style="color:#b5cea8">5</span> <span style="color:#b5cea8">1</span>)</div><div>      (secondsToDiffTime <span style="color:#b5cea8">34250</span>))</div><div>    , DbNumber <span style="color:#b5cea8">9001</span></div><div>    , DbString <span style="color:#ce9178">"Hello, world!"</span></div><div>    , DbDate (UTCTime</div><div>             (fromGregorian <span style="color:#b5cea8">1921</span> <span style="color:#b5cea8">5</span> <span style="color:#b5cea8">1</span>)</div><div>             (secondsToDiffTime <span style="color:#b5cea8">34123</span>))</div><div>    ]</div></div><div><div style="font-family:Arial;font-size:13px"><br></div></div></div><div style="font-family:Arial;font-size:13px"><br></div><div style="font-family:Arial;font-size:13px">question from textbook is : write a function that filters for DbDate values and returns a list of the UTCTime values inside them.<br></div><div style="font-family:Arial;font-size:13px"><br></div><div style="font-family:Arial;font-size:13px"><br></div><div style="font-family:Arial;font-size:13px">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.</div><div style="font-family:Arial;font-size:13px"><br></div><div style="font-family:Arial;font-size:13px">thanks in advance.</div><div style="font-family:Arial;font-size:13px"><br></div><div style="font-family:Arial;font-size:13px">best,</div><div style="font-family:Arial;font-size:13px"><br></div><div style="font-family:Arial;font-size:13px"><br></div></div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div></div>