<div dir="ltr"><div><div><div>Hey Matt,<br><br></div>cool idea! Also it looks like such a tool could 'solve' stream fusion: <a href="https://ghc.haskell.org/trac/ghc/ticket/915#comment:52" target="_blank">https://ghc.haskell.org/trac/<wbr>ghc/ticket/915#comment:52</a><br><br></div>Greetings<br></div>Sebastian<br></div><div class="gmail_extra"><br><div class="gmail_quote">2018-02-27 18:01 GMT+01:00 Joachim Breitner <span dir="ltr"><<a href="mailto:mail@joachim-breitner.de" target="_blank">mail@joachim-breitner.de</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
something like this would be great. I don’t have a sense yet of what<br>
“something” should be like.<br>
<span class=""><br>
<br>
Am Dienstag, den 27.02.2018, 09:59 +0000 schrieb Matthew Pickering:<br>
> To go back to the power example, the recursive<br>
> condition would have to be an inductively defined natural (data N = Z<br>
> | S N) rather than an Int as the comparison operator for integers<br>
> can't be evaluated by the optimiser.<br>
<br>
</span>Sure they can:<br>
<br>
$ cat ConstantFolding.hs<br>
{-# LANGUAGE TemplateHaskell #-}<br>
{-# OPTIONS_GHC -fplugin=Test.Inspection.<wbr>Plugin #-}<br>
module ConstantFolding where<br>
<br>
import Test.Inspection<br>
<br>
ltInt :: Bool<br>
ltInt = (3::Int) > 2<br>
<br>
ltInteger :: Bool<br>
ltInteger = (3::Integer) > 2<br>
<br>
true :: Bool<br>
true = True<br>
<br>
<br>
inspect $ 'ltInt === 'true<br>
inspect $ 'ltInteger === 'true<br>
<br>
$ ghc -O ConstantFolding.hs<br>
[1 of 1] Compiling ConstantFolding ( ConstantFolding.hs,<br>
ConstantFolding.o )<br>
ConstantFolding.hs:17:1: ltInt === true passed.<br>
ConstantFolding.hs:18:1: ltInteger === true passed.<br>
inspection testing successful<br>
expected successes: 2<br>
<br>
<br>
<br>
As an alternative with a maybe simpler user interface (and probably<br>
less power), I wonder if we can create a magic function<br>
> compileTimeWHNF :: a -> a<br>
or<br>
> compileTimeNF :: a -> a<br>
and a GHC core plugin (or eventually built-in thing) that finds these<br>
magic functions and evaluates their arguments, using the simplifier.<br>
<br>
<br>
Cheers,<br>
Joachim<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Joachim Breitner<br>
<a href="mailto:mail@joachim-breitner.de">mail@joachim-breitner.de</a><br>
<a href="http://www.joachim-breitner.de/" rel="noreferrer" target="_blank">http://www.joachim-breitner.<wbr>de/</a><br>
</font></span><br>______________________________<wbr>_________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div>