Re: [Haskell-cafe] Printing the empty list.

2011-07-02 Thread Henning Thielemann

On 01.07.2011 00:58, Joshua Ball wrote:

GHCi seems to be clever about some things:

If I try to print the empty list in ghci, I encounter no problems:

Prelude>  []
[]
Prelude>  show []
"[]"
Prelude>  print []
[]

Even though the type of the list is clearly unknown, it must be
picking SOME type. (why does it print [] instead of "")?

If I write a program in a file and load it in

main = print []

Then I get the ambiguous type variable error that I would expect. Why
doesn't ghci generate this error at the prompt?


GHCi will warn you, that type defaulting was used, if you start it with

ghci -Wall


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Printing the empty list.

2011-07-01 Thread Ryan Ingram
Figuring out how to tell what type ghci is defaulting to was an interesting
exercise.  The sum [] trick seemed cool, so I tried a variant:

Prelude> let f xs = const xs $ show xs
Prelude> f []
[]
Prelude> :t it
it :: [()]

  -- ryan


On Thu, Jun 30, 2011 at 6:44 PM, Ivan Lazar Miljenovic <
ivan.miljeno...@gmail.com> wrote:

> On 1 July 2011 11:35, Brent Yorgey  wrote:
> > On Fri, Jul 01, 2011 at 09:05:05AM +1000, Ivan Lazar Miljenovic wrote:
> >> On 1 July 2011 08:58, Joshua Ball  wrote:
> >> > GHCi seems to be clever about some things:
> >> >
> >> > If I try to print the empty list in ghci, I encounter no problems:
> >> >
> >> > Prelude> []
> >> > []
> >> > Prelude> show []
> >> > "[]"
> >> > Prelude> print []
> >> > []
> >> >
> >> > Even though the type of the list is clearly unknown, it must be
> >> > picking SOME type. (why does it print [] instead of "")?
> >>
> >> Type defaulting: if you don't specify a type, then ghci makes it
> >> [Integer].
> >
> > In this case I'm pretty sure it is [()] since there is only a Show
> > constraint.  If there were a Num constraint it would pick
> > Integer.
>
> Yeah, I forgot about ()
>
> --
> Ivan Lazar Miljenovic
> ivan.miljeno...@gmail.com
> IvanMiljenovic.wordpress.com
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Printing the empty list.

2011-06-30 Thread Ivan Lazar Miljenovic
On 1 July 2011 11:35, Brent Yorgey  wrote:
> On Fri, Jul 01, 2011 at 09:05:05AM +1000, Ivan Lazar Miljenovic wrote:
>> On 1 July 2011 08:58, Joshua Ball  wrote:
>> > GHCi seems to be clever about some things:
>> >
>> > If I try to print the empty list in ghci, I encounter no problems:
>> >
>> > Prelude> []
>> > []
>> > Prelude> show []
>> > "[]"
>> > Prelude> print []
>> > []
>> >
>> > Even though the type of the list is clearly unknown, it must be
>> > picking SOME type. (why does it print [] instead of "")?
>>
>> Type defaulting: if you don't specify a type, then ghci makes it
>> [Integer].
>
> In this case I'm pretty sure it is [()] since there is only a Show
> constraint.  If there were a Num constraint it would pick
> Integer.

Yeah, I forgot about ()

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Printing the empty list.

2011-06-30 Thread Brent Yorgey
On Fri, Jul 01, 2011 at 09:05:05AM +1000, Ivan Lazar Miljenovic wrote:
> On 1 July 2011 08:58, Joshua Ball  wrote:
> > GHCi seems to be clever about some things:
> >
> > If I try to print the empty list in ghci, I encounter no problems:
> >
> > Prelude> []
> > []
> > Prelude> show []
> > "[]"
> > Prelude> print []
> > []
> >
> > Even though the type of the list is clearly unknown, it must be
> > picking SOME type. (why does it print [] instead of "")?
> 
> Type defaulting: if you don't specify a type, then ghci makes it
> [Integer].

In this case I'm pretty sure it is [()] since there is only a Show
constraint.  If there were a Num constraint it would pick
Integer.

  Prelude> sum []
  0
  Prelude> :t it
  it :: Integer

-Brent

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Printing the empty list.

2011-06-30 Thread Ivan Lazar Miljenovic
On 1 July 2011 08:58, Joshua Ball  wrote:
> GHCi seems to be clever about some things:
>
> If I try to print the empty list in ghci, I encounter no problems:
>
> Prelude> []
> []
> Prelude> show []
> "[]"
> Prelude> print []
> []
>
> Even though the type of the list is clearly unknown, it must be
> picking SOME type. (why does it print [] instead of "")?

Type defaulting: if you don't specify a type, then ghci makes it [Integer].

> If I write a program in a file and load it in
>
> main = print []
>
> Then I get the ambiguous type variable error that I would expect. Why
> doesn't ghci generate this error at the prompt?

Because ghc doesn't do type defaulting.

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Printing the empty list.

2011-06-30 Thread Brandon Allbery
On Thu, Jun 30, 2011 at 18:58, Joshua Ball  wrote:
> GHCi seems to be clever about some things:

GHCi uses extended defaulting rules unless told otherwise, so in the
absence of anything else it uses () as the type.  You can enable this
in GHC as well, with -XExtendedDefaultRules.  See
http://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluation.html#extended-default-rules

-- 
brandon s allbery                                      allber...@gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Printing the empty list.

2011-06-30 Thread Joshua Ball
GHCi seems to be clever about some things:

If I try to print the empty list in ghci, I encounter no problems:

Prelude> []
[]
Prelude> show []
"[]"
Prelude> print []
[]

Even though the type of the list is clearly unknown, it must be
picking SOME type. (why does it print [] instead of "")?

If I write a program in a file and load it in

main = print []

Then I get the ambiguous type variable error that I would expect. Why
doesn't ghci generate this error at the prompt?

-- 
Borrow my books: http://goo.gl/UBbSH

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe