Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,828
    • Issues 4,828
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 452
    • Merge requests 452
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #2222

Closed
Open
Created Apr 15, 2008 by alfonso.acosta@gmail.com@trac-alfonso.acosta

Template Haskell: reify returns incorrect types when ommiting type signatures

Replicable with GHC versions 6.8.2 and 6.9 (20080219 snapshot).

Workaround: supply type signatures.

See the following examples:

ReifyPlusTypeInferenceBugs.hs

{-# LANGUAGE TemplateHaskell #-}
module ReifyPlusTypeInferenceBugs where

import Language.Haskell.TH

-- First problem:
--  * reify doesn't return the expected type of names binded to
--    polymorphic expressions

-- a :: Num a => a
-- uncommenting the line above fixes the problem 
a = 1

-- The following splice should print 
-- "inside b: forall a_0 . GHC.Num.Num a_0 => a_0"
-- but instead, it merely prints a type variable "inside b: t_0"
b = $(do VarI _ t _ _ <- reify 'a
         runIO $ putStrLn ("inside b: " ++ pprint t)
         [| undefined |]) 


-- Second problem:
--  * reify doesn't return the expected type of names binded to
--    TH-spliced expressions if no explicit type signature
--    declaration is provided.


-- c :: Bool
-- uncommenting the line above fixes the problem 
c = $([| True |])


-- this splice should print "inside d: GHC.Base.Bool" 
-- but, again, it prints just a type variable: "inside d: t_0"
d = $(do VarI _ t _ _ <- reify 'c
         runIO $ putStrLn ("inside d: " ++ pprint t)
         [| undefined |] )

-- Strangely enough, reify works differently if called inside a declaration 
-- splice. This time, the type returned is closer to be right
-- but unnecesary type variables are included:
-- "type of c: forall a_0 a_1 . GHC.Base.Bool"
$(do VarI _ t _ _ <- reify 'c
     runIO $ putStrLn ("type of c: " ++ pprint t)
     return [] )


-- Even more strange is the fact that the order of declaration of 
-- splices seems to matter. Declaring the exact example again ....

-- e :: Bool
-- uncommenting the line above solves the problem
e = $([| True |])

-- this splice works as expected!!! ???
-- "inside f: GHC.Base.Bool"
f = $(do VarI _ t _ _ <- reify 'e
         runIO $ putStrLn ("inside f: " ++ pprint t)
         [| undefined |] )

-- Here, we still get unnecesary variables, but, for some reason,
-- _just_ one in this case:
-- "type of e: forall a_0 . GHC.Base.Bool" 
$(do VarI _ t _ _ <- reify 'e
     runIO $ putStrLn ("type of e: " ++ pprint t)
     return [] )
Trac metadata
Trac field Value
Version 6.8.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
Test case
Differential revisions
BlockedBy
Related
Blocking
CC alfonso.acosta@gmail.com
Operating system Multiple
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking