
Hi, something like this would be great. I don’t have a sense yet of what “something” should be like. Am Dienstag, den 27.02.2018, 09:59 +0000 schrieb Matthew Pickering:
To go back to the power example, the recursive condition would have to be an inductively defined natural (data N = Z | S N) rather than an Int as the comparison operator for integers can't be evaluated by the optimiser.
Sure they can: $ cat ConstantFolding.hs {-# LANGUAGE TemplateHaskell #-} {-# OPTIONS_GHC -fplugin=Test.Inspection.Plugin #-} module ConstantFolding where import Test.Inspection ltInt :: Bool ltInt = (3::Int) > 2 ltInteger :: Bool ltInteger = (3::Integer) > 2 true :: Bool true = True inspect $ 'ltInt === 'true inspect $ 'ltInteger === 'true $ ghc -O ConstantFolding.hs [1 of 1] Compiling ConstantFolding ( ConstantFolding.hs, ConstantFolding.o ) ConstantFolding.hs:17:1: ltInt === true passed. ConstantFolding.hs:18:1: ltInteger === true passed. inspection testing successful expected successes: 2 As an alternative with a maybe simpler user interface (and probably less power), I wonder if we can create a magic function
compileTimeWHNF :: a -> a or compileTimeNF :: a -> a and a GHC core plugin (or eventually built-in thing) that finds these magic functions and evaluates their arguments, using the simplifier.
Cheers, Joachim -- Joachim Breitner mail@joachim-breitner.de http://www.joachim-breitner.de/