<div dir="ltr">To elaborate, EpochTime is just a type synonym for CTime. CTime has a constructor CTime Int64, so you can pattern match on it to get the Int64 inside. Int64 has a ToJSON instance, so you can run toJSON on it to get a Value.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 16, 2015 at 2:30 PM, Patrick Chilton <span dir="ltr"><<a href="mailto:chpatrick@gmail.com" target="_blank">chpatrick@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">There's no need to go to Integer, just use this:<div><br></div><div>epochToJSON :: EpochTime -> Value</div><div>epochToJSON (CTime t) = toJSON t</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 16, 2015 at 12:19 PM, Bram Neijt <span dir="ltr"><<a href="mailto:bneijt@gmail.com" target="_blank">bneijt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm sorry, but as a newby I can't seem to get it to work.<br>
<br>
If I use<br>
return (mtime :: Integer)<br>
I get<br>
src/Main.hs:21:13:<br>
Couldn't match type ‘Foreign.C.Types.CTime’ with ‘Integer’<br>
Expected type: Integer<br>
Actual type: System.Posix.Types.EpochTime<br>
In the first argument of ‘return’, namely ‘(mtime :: Integer)’<br>
In a stmt of a 'do' block: return (mtime :: Integer)<br>
<br>
If I use<br>
return (toInteger mtime)<br>
I get<br>
src/Main.hs:21:13:<br>
No instance for (Integral System.Posix.Types.EpochTime)<br>
arising from a use of ‘toInteger’<br>
In the first argument of ‘return’, namely ‘(toInteger mtime)’<br>
In a stmt of a 'do' block: return (toInteger mtime)<br>
In the expression:<br>
do { status <- getFileStatus filepath;<br>
let mtime = modificationTime status;<br>
return (toInteger mtime) }<br>
<br>
What am I doing wrong here? How would I pattern match to convert the type?<br>
<br>
Greetings,<br>
<br>
Bram<br>
<br>
PS Code is still<br>
<a href="https://github.com/bneijt/httpmtimeline/blob/master/src/Main.hs#L21" rel="noreferrer" target="_blank">https://github.com/bneijt/httpmtimeline/blob/master/src/Main.hs#L21</a><br>
Versions<br>
cabal-install version 1.22.2.0<br>
using version 1.22.2.0 of the Cabal library<br>
The Glorious Glasgow Haskell Compilation System, version 7.10.1<br>
<div><div><br>
<br>
<br>
<br>
<br>
On Tue, Sep 15, 2015 at 6:48 PM, David Kraeutmann <<a href="mailto:kane@kane.cx" target="_blank">kane@kane.cx</a>> wrote:<br>
> EpochTime is an instance of Integral. You can just use toInteger ::<br>
> Integral a => a -> Integer.<br>
> On 9/15/2015 6:42 PM, Bram Neijt wrote:<br>
>> Dear Haskell cafe,<br>
>><br>
>> I want to convert form<br>
>><br>
>> mtime :: System.Posix.Types.EpochTime<br>
>><br>
>> to something aeson can eat without having to define an instance. I<br>
>> choose Integer.<br>
>><br>
>> My current solution[1] is just using (read . show). I know, ugly, but<br>
>> the only thing I could get going.<br>
>><br>
>> What is the proper way to convert System.Posix.Types.EpochTime to<br>
>> Integer or something else aeson will automatically convert without<br>
>> making a ToJSON instance?<br>
>><br>
>> As a beginner I wonder: is there a general way to go about finding<br>
>> conversion paths between types?<br>
>><br>
>><br>
>> Greetings,<br>
>><br>
>> Bram Neijt<br>
>><br>
>> [1] <a href="https://github.com/bneijt/httpmtimeline/blob/master/src/Main.hs#L21" rel="noreferrer" target="_blank">https://github.com/bneijt/httpmtimeline/blob/master/src/Main.hs#L21</a><br>
>> _______________________________________________<br>
>> Haskell-Cafe mailing list<br>
>> <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
>> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>