Skip to content

Instantly share code, notes, and snippets.

@hiratara
Created July 10, 2012 12:00
Show Gist options
  • Save hiratara/3082903 to your computer and use it in GitHub Desktop.
Save hiratara/3082903 to your computer and use it in GitHub Desktop.
ghc-mod complains strange warnings about Template Haskell
% ~/Library/Haskell/bin/ghc-mod check SummTest.hs
SummTest.hs:5:14:Warning: This binding for `x' shadows the existing binding bound at SummTest.hs:5:14
SummTest.hs:5:14:Warning: This binding for `x' shadows the existing binding bound at SummTest.hs:5:14
% ghc -Wall SummTest.hs
[1 of 2] Compiling Summ ( Summ.hs, Summ.o )
[2 of 2] Compiling SummTest ( SummTest.hs, SummTest.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package array-0.4.0.0 ... linking ... done.
Loading package deepseq-1.3.0.0 ... linking ... done.
Loading package containers-0.4.2.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
SummTest.hs:6:14:
Warning: This binding for `x' shadows the existing binding
bound at SummTest.hs:6:14
SummTest.hs:6:14:
Warning: This binding for `x' shadows the existing binding
bound at SummTest.hs:6:14
% ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.4.1
% sw_vers
ProductName: Mac OS X
ProductVersion: 10.7.4
BuildVersion: 11E53
{-# LANGUAGE TemplateHaskell #-}
{- This code is copied from https://doc-0k-38-docs.googleusercontent.com/docs/securesc/aajuopgtt5qibldtm8nm9ddqvkj2htqk/3tnn2mmp1rc0kv1q7k0cvtu4m487sbn9/1341907200000/10578434965449041783/04665698165796945800/0B4BgTwf_ng_TM2MxZjJjZjctMTQ0OS00YzcwLWE5N2QtMDI0YzE4NGUwZDM3?nonce=40t1sdu1fftu4&user=04665698165796945800&hash=slcu2anrh4asf3hncs30cti9qbg5amho -}
module Summ where
import Language.Haskell.TH
summ :: Int -> Q Exp
summ n = summ' n [| 0 :: Int |]
where
summ' 0 code = code
summ' n' code = [| \x -> $(summ' (n' - 1) [| $code + x :: Int |]) |]
{-# LANGUAGE TemplateHaskell #-}
module SummTest where
import Summ
sumThree :: Int -> Int -> Int -> Int
sumThree = $(summ 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment