Re: [Haskell-cafe] type inference question

2009-10-09 Thread minh thu
2009/10/9 wren ng thornton : > Cristiano Paris wrote: >> >> On Thu, Oct 8, 2009 at 12:48 PM, Lennart Augustsson wrote: >>> >>> The reason a gets a single type is the monomorphism restriction (read >>> the report). >>> Using NoMonomorphismRestriction your example with a works fine. >> >> Could you e

Re: [Haskell-cafe] type inference question

2009-10-09 Thread wren ng thornton
Cristiano Paris wrote: On Thu, Oct 8, 2009 at 12:48 PM, Lennart Augustsson wrote: The reason a gets a single type is the monomorphism restriction (read the report). Using NoMonomorphismRestriction your example with a works fine. Could you explain why, under NoMonomorphismRestriction, this type

Re: Re[2]: [Haskell-cafe] type inference question

2009-10-08 Thread Lennart Augustsson
Indeed, the types foo :: forall a . (Num a) => a -> (Int, Float) and foo :: (forall a . (Num a) => a) -> (Int, Float) are quite different. The first one say, I (foo) can handle any kind of numeric 'a' you (the caller) can pick. You (the caller) get to choose exactly what type you give me. The

Re[2]: [Haskell-cafe] type inference question

2009-10-08 Thread Bulat Ziganshin
Hello Cristiano, Thursday, October 8, 2009, 7:14:20 PM, you wrote: > Could you explain why, under NoMonomorphismRestriction, this typechecks: > let a = 1 in (a + (1 :: Int),a + (1 :: Float)) > while this not: > foo :: Num a => a -> (Int,Float) > foo k = (k + (1 :: Int), k + (1.0 :: Float)) i

Re: [Haskell-cafe] type inference question

2009-10-08 Thread minh thu
2009/10/8 Cristiano Paris : > On Thu, Oct 8, 2009 at 12:48 PM, Lennart Augustsson > wrote: >> The reason a gets a single type is the monomorphism restriction (read >> the report). >> Using NoMonomorphismRestriction your example with a works fine. > > Could you explain why, under NoMonomorphismRest

Re: [Haskell-cafe] type inference question

2009-10-08 Thread Cristiano Paris
On Thu, Oct 8, 2009 at 12:48 PM, Lennart Augustsson wrote: > The reason a gets a single type is the monomorphism restriction (read > the report). > Using NoMonomorphismRestriction your example with a works fine. Could you explain why, under NoMonomorphismRestriction, this typechecks: let a = 1 i

Re: [Haskell-cafe] type inference question

2009-10-08 Thread minh thu
Thanks all! Thu 2009/10/8 Lennart Augustsson : > The reason a gets a single type is the monomorphism restriction (read > the report). > Using NoMonomorphismRestriction your example with a works fine. > > On Thu, Oct 8, 2009 at 12:29 PM, Cristiano Paris wrote: >> On Thu, Oct 8, 2009 at 11:04 AM, m

Re: [Haskell-cafe] type inference question

2009-10-08 Thread Lennart Augustsson
The reason a gets a single type is the monomorphism restriction (read the report). Using NoMonomorphismRestriction your example with a works fine. On Thu, Oct 8, 2009 at 12:29 PM, Cristiano Paris wrote: > On Thu, Oct 8, 2009 at 11:04 AM, minh thu wrote: >> Hi, >> >> I'd like to know what are the

Re: [Haskell-cafe] type inference question

2009-10-08 Thread Deniz Dogan
2009/10/8 Cristiano Paris : > On Thu, Oct 8, 2009 at 11:04 AM, minh thu wrote: >> Hi, >> >> I'd like to know what are the typing rules used in Haskell (98 is ok). >> >> Specifically, I'd like to know what makes >> >> let i = \x -> x in (i True, i 1) >> >> legal, and not >> >> let a = 1 in (a + (1

Re: [Haskell-cafe] type inference question

2009-10-08 Thread Cristiano Paris
On Thu, Oct 8, 2009 at 11:04 AM, minh thu wrote: > Hi, > > I'd like to know what are the typing rules used in Haskell (98 is ok). > > Specifically, I'd like to know what makes > > let i = \x -> x in (i True, i 1) > > legal, and not > > let a = 1 in (a + (1 :: Int), a + (1.0 :: Float)) > > Is it co

Re: [Haskell-cafe] type inference question

2009-10-08 Thread minh thu
2009/10/8 Jochem Berndsen : > minh thu wrote: >> Also, I'd like to know why >> >> id id True >> >> is permitted but not >> >> (\f -> f f True) id > > If you want to do this, answer the question "what is the type of (\f -> > f f True)"? > You can do this, by the way, using rank-2 types: >> {-# LANGU

Re: [Haskell-cafe] type inference question

2009-10-08 Thread Jochem Berndsen
minh thu wrote: > Also, I'd like to know why > > id id True > > is permitted but not > > (\f -> f f True) id If you want to do this, answer the question "what is the type of (\f -> f f True)"? You can do this, by the way, using rank-2 types: > {-# LANGUAGE Rank2Types, PatternSignatures #-} > thisI

Re: [Haskell-cafe] type inference question

2009-10-08 Thread Martijn van Steenbergen
minh thu wrote: Also, I'd like to know why id id True is permitted but not (\f -> f f True) id Because this requires rank-2 types: Prelude> :set -XScopedTypeVariables Prelude> :set -XRank2Types Prelude> (\(f :: forall a. a -> a) -> f f True) id True HTH, Martijn. __

[Haskell-cafe] type inference question

2009-10-08 Thread minh thu
Hi, I'd like to know what are the typing rules used in Haskell (98 is ok). Specifically, I'd like to know what makes let i = \x -> x in (i True, i 1) legal, and not let a = 1 in (a + (1 :: Int), a + (1.0 :: Float)) Is it correct that polymorphic functions can be used polymorphically (in multi