An idea for a different style of metaprogramming evaluation using the optimiser

Sebastian Graf sgraf1337 at gmail.com
Tue Feb 27 18:35:18 UTC 2018


Hey Matt,

cool idea! Also it looks like such a tool could 'solve' stream fusion:
https://ghc.haskell.org/trac/ghc/ticket/915#comment:52

Greetings
Sebastian

2018-02-27 18:01 GMT+01:00 Joachim Breitner <mail at joachim-breitner.de>:

> 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 at joachim-breitner.de
>   http://www.joachim-breitner.de/
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20180227/a5100a59/attachment.html>


More information about the ghc-devs mailing list