[Haskell-cafe] Re: Implicit newtype unwrapping
aslatter at gmail.com
Thu Dec 3 23:33:06 EST 2009
On Thu, Dec 3, 2009 at 9:10 PM, Antoine Latter <aslatter at gmail.com> wrote:
> On Thu, Dec 3, 2009 at 6:00 PM, Joachim Breitner
> <mail at joachim-breitner.de> wrote:
>> But when I uncommented the definition of toFoo and fromfoo, I got:
>> Couldn't match expected type `Foo' against inferred type `Int'
>> In the expression: id
>> In the definition of `toFoo': toFoo = id
>> In the second argument of `openNewtype', namely
>> `[d| nullFoo :: Foo
>> nullFoo = 0
>> toFoo :: Int -> Foo
>> toFoo = id
>> .... |]'
>> And just now, after writing half the code, I find out that $( fun
>> [d|...|] ) runs the type checker on the declarations before passing them
>> to fun, which of course kills my whole approach here, as only having the
>> declarations pass through openNewType will make them type check.
>> Is there any way to pass declarations to a TH function so that their
>> names are resolved, but their type is not checked (or, alternatively,
>> type errors are ignored).
>> If not, what would be a sane work-around?
> You could switch over to using a quasi-quoter. I think there's one on
> hackage for parsing haskell declarations you might be able to start
> More on GHC quasi-quotations:
So I gave it a try:
But it doesn't work, and I don't understand TH enough to figure out
why. I'm guessing that the TH code can't associate the parsed type
name with the passed-in type name, so we don't know to do the proper
More information about the Haskell-Cafe