2

Why does the following fail to compile (on GHC 7.4.2)?

{-# LANGUAGE TemplateHaskell #-}

f1 = $([| id |])

main = print $ (f1 (42 :: Int), f1 (42 :: Integer))

Note that the following compiles fine:

{-# LANGUAGE TemplateHaskell #-}

f1 = id -- Don't use template Haskell here.

main = print $ (f1 (42 :: Int), f1 (42 :: Integer))

Is there a language extension I can use to make the former compile?

I know the Template Haskell seems silly in this example, but it's a simplified version of a more complex problem, which requires Template Haskell to process arbitrary sized tuples.

1 Answer 1

4

Apparently f1 is assigned the type Integer -> Integer instead of the more general a -> a for some reason. Adding an explicit type signature makes your example compile fine for me:

{-# LANGUAGE TemplateHaskell #-}

f1 :: a -> a
f1 = $([| id |])

main = print $ (f1 (42 :: Int), f1 (42 :: Integer))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.