<div dir="ltr">I've done something similar recently for an emulator I'm writing. It essentially turns GHCI into a debugger for free:<div><br></div><div><font face="monospace, monospace">newtype Run = Run (forall a. Emu a -> IO a)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">start :: FilePath -> IO Run</font></div><div><font face="monospace, monospace">breakpoint :: Word16 -> Emu ()</font></div><div><font face="monospace, monospace">readMem :: Word16 -> Emu Word8</font></div><div><font face="monospace, monospace">step :: Emu ()</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">Run emu <- start "foo.rom"</font></div><div><font face="monospace, monospace">emu $ breakpoint 0x4567</font></div><div><font face="monospace, monospace">emu $ readMem 0xdead</font></div><div><font face="monospace, monospace">emu step</font></div><div><br></div><div>etc</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 15, 2015 at 4:57 PM, Paolino <span dir="ltr"><<a href="mailto:paolo.veronelli@gmail.com" target="_blank">paolo.veronelli@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"><div><div>It worked without adding JSON constraint in the newtype. <br>I can do whatever I want with 'a'. <br><br></div><div>A simplified example where the database module is not polluted with future use of the query results.<br><br><a href="http://lpaste.net/134541#a134548" target="_blank">http://lpaste.net/134541#a134548</a><br></div><br></div><div> I tried refactoring common code ...... not easy<br><br></div><div>Thanks again<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>paolino<br></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2015-06-15 16:26 GMT+02:00 Paolino <span dir="ltr"><<a href="mailto:paolo.veronelli@gmail.com" target="_blank">paolo.veronelli@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Thanks, I'd never have guessed. <br>I have a GADT Get a where I define a protocol to query a database where 'a' is the return type a.<br></div>Then prepare :: IO (Get a -> ErrorAndWriterMonad a) is opening the database and return the query function.<br></div><div>I suspect I have to insert the constraint in the wrapper to let transform 'a' to JSON or String, which I don't like. I'll have to dig it.<br><br></div><div>Regards<span><font color="#888888"><br><br></font></span></div><span><font color="#888888"><div>paolino<br></div><div><br></div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2015-06-15 16:18 GMT+02:00 Patrick Chilton <span dir="ltr"><<a href="mailto:chpatrick@gmail.com" target="_blank">chpatrick@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yes, but you have to wrap it up:<br><div><br></div><div><div><font face="monospace, monospace">{-# LANGUAGE RankNTypes #-}</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">-- obviously not to useful for this example :)</font></div><div><font face="monospace, monospace">newtype Id = Id (forall a. a -> a)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">f :: IO Id</font></div><div><font face="monospace, monospace">f = return (Id id)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">main = do</font></div><div><font face="monospace, monospace">  Id g <- f</font></div><span><div><font face="monospace, monospace">  print $ g 1</font></div><div><font face="monospace, monospace">  print $ g "ciao"</font></div></span></div><div><br></div><div>Can I ask what you're trying to do with this?</div><div><br></div><div>Patrick</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Mon, Jun 15, 2015 at 3:11 PM, Paolino <span dir="ltr"><<a href="mailto:paolo.veronelli@gmail.com" target="_blank">paolo.veronelli@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Hello list, I'm trying to accomplish something along this line<br><div><br>{-# LANGUAGE ScopedTypeVariables #-}<br><br>f :: IO (a -> a)<br>f = return id<br><br>main = do<br>  (g :: a -> a) <- f<br>  print $ g 1<br>  print $ g "ciao"<br><br></div><div><br><br></div><div>Is it possible or I have to call f more than once to get different g's<br><br><br></div><div>Thanks<span><font color="#888888"><br></font></span></div><span><font color="#888888"><div><br></div><div>paolino<br></div></font></span></div>
<br></div></div>_______________________________________________<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></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>