[Haskell-beginners] what type is 'Val 9' when 'Val Int' a ctor
for 'Expr e'?
Larry Evans
cppljevans at suddenlink.net
Wed Oct 22 23:36:09 EDT 2008
On 10/22/08 19:52, Daniel Fischer wrote:
> Am Mittwoch, 22. Oktober 2008 23:44 schrieb Antoine Latter:
>
>> On Wed, Oct 22, 2008 at 4:10 PM, Jason Dusek <jason.dusek at gmail.com> wrote:
>>
>>> Can you explain why you think you need that annotation? I
>>> can't see an ambiguous interpretation of your code.
>>>
>> The confusion is that the 'Val' constructor is for the 'Expr' type,
>> which has a phantom type parameter in its type constructor.
>>
>> Can you load that up into GHCi and type:
>>
>>> :t val_9
>>>
>> which should cause GHCi to print out what it thinks the type of that
>> expression is.
>>
>> -Antoine
>>
>
> ghci correctly thinks that has the type Expr e. Much like
> *Main> :t []
> [] :: [a]
>
> I think what goes on here is defaulting (deviating from Section 4.3.4 of the
> report, but it's the same deviation that allows [] to be printed). To print
> it, ghci picks some default type for e, probably Integer, as the defaut
> default is (Integer, Double), doesn't influence the result of show.
> If you muck around with the Show instance, you can easily get compilation
> errors like "Ambiguous type variable..." (e.g. if you add a (Show e)
> constraint to the Show instance for (Expr e), but not if you add a (Num e) or
> an (Integral e) constraint).
>
Thanks Deaniel. The fog in my head begins to clear.
I took Antoine's suggestion and got:
<---cut here ---
GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help
Loading package base ... linking ... done.
Prelude> :load
"/home/evansl/prog_dev/haskell/my-code/uniplate.try.phantom.hs"
[1 of 1] Compiling Main (
/home/evansl/prog_dev/haskell/my-code/uniplate.try.phantom.hs, interpreted )
Ok, modules loaded: Main.
*Main> let val_9 = Val 9
Loading package mtl-1.1.0.0 ... linking ... done.
Loading package array-0.1.0.0 ... linking ... done.
Loading package containers-0.1.0.1 ... linking ... done.
Loading package uniplate-1.2.0.1 ... linking ... done.
*Main> :t val_9
val_9 :: Expr e
*Main> print val_9
Val 9
*Main>
>---cut here---
I guess the phantom type mentioned in Antoine's post is the e in:
val_9::Expr e
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20081022/23562c71/attachment-0001.htm
More information about the Beginners
mailing list