16 Nov 08:10 2012

## need help with understanding expression

I am having hard time understanding how removing the  outer parenthesis in

(max.(+1)) 2 2

to

max.(+1) 2 2

changes the meaning of expression.

My expectation was that "max.(+1) takes two numbers and returns the max as defined in the type:

:t max.(+1)
max.(+1) :: (Ord b, Num b) => b -> b -> b

With parenthesis it does what I expect it to:

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude>  (max.(+1)) 2 2
3

But if I remove the parenthesis I get a beast that I have no idea what its type signature mean any more

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude> :t max.(+1) 2 2
max.(+1) 2 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

How did removal of parenthesis changed the meaning?      How do you interpret the type:  "(Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b"?

Thanks

--
Daryoush

Weblog:  http://onfp.blogspot.com/
```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
16 Nov 08:19 2012

### Re: need help with understanding expression

Hi Daryoush,

I recommend you try these experiments first, and then reply back if you're still confused.

:t max

:t (+1)

:t max . (+1)

:t (+1) 2

:t (.)

On Fri, Nov 16, 2012 at 7:10 AM, Daryoush Mehrtash wrote:
I am having hard time understanding how removing the  outer parenthesis in

(max.(+1)) 2 2

to

max.(+1) 2 2

changes the meaning of expression.

My expectation was that "max.(+1) takes two numbers and returns the max as defined in the type:

:t max.(+1)
max.(+1) :: (Ord b, Num b) => b -> b -> b

With parenthesis it does what I expect it to:

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude>  (max.(+1)) 2 2
3

But if I remove the parenthesis I get a beast that I have no idea what its type signature mean any more

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude> :t max.(+1) 2 2
max.(+1) 2 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

How did removal of parenthesis changed the meaning?      How do you interpret the type:  "(Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b"?

Thanks

--
Daryoush

Weblog:  http://onfp.blogspot.com/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
16 Nov 08:46 2012

### Re: need help with understanding expression

I see the point with :t (.)  that

max.(+1) 2 2

is the same as

max. 3 2

Which is not what I want.

But I have no idea what the type signature of this expression mean now

Prelude> :t max. 3 2
max. 3 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

Any idea?

Daryoush

On Thu, Nov 15, 2012 at 11:19 PM, Ramana Kumar wrote:
Hi Daryoush,

I recommend you try these experiments first, and then reply back if you're still confused.

:t max

:t (+1)

:t max . (+1)

:t (+1) 2

:t (.)

On Fri, Nov 16, 2012 at 7:10 AM, Daryoush Mehrtash wrote:
I am having hard time understanding how removing the  outer parenthesis in

(max.(+1)) 2 2

to

max.(+1) 2 2

changes the meaning of expression.

My expectation was that "max.(+1) takes two numbers and returns the max as defined in the type:

:t max.(+1)
max.(+1) :: (Ord b, Num b) => b -> b -> b

With parenthesis it does what I expect it to:

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude>  (max.(+1)) 2 2
3

But if I remove the parenthesis I get a beast that I have no idea what its type signature mean any more

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude> :t max.(+1) 2 2
max.(+1) 2 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

How did removal of parenthesis changed the meaning?      How do you interpret the type:  "(Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b"?

Thanks

--
Daryoush

Weblog:  http://onfp.blogspot.com/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

--
Daryoush

Weblog:  http://onfp.blogspot.com/
```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
16 Nov 08:56 2012

### Re: need help with understanding expression

Another experiment may be revealing:

:t 3 2

On Fri, Nov 16, 2012 at 7:46 AM, Daryoush Mehrtash wrote:
I see the point with :t (.)  that

max.(+1) 2 2

is the same as

max. 3 2

Which is not what I want.

But I have no idea what the type signature of this expression mean now

Prelude> :t max. 3 2
max. 3 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

Any idea?

Daryoush

On Thu, Nov 15, 2012 at 11:19 PM, Ramana Kumar wrote:
Hi Daryoush,

I recommend you try these experiments first, and then reply back if you're still confused.

:t max

:t (+1)

:t max . (+1)

:t (+1) 2

:t (.)

On Fri, Nov 16, 2012 at 7:10 AM, Daryoush Mehrtash wrote:
I am having hard time understanding how removing the  outer parenthesis in

(max.(+1)) 2 2

to

max.(+1) 2 2

changes the meaning of expression.

My expectation was that "max.(+1) takes two numbers and returns the max as defined in the type:

:t max.(+1)
max.(+1) :: (Ord b, Num b) => b -> b -> b

With parenthesis it does what I expect it to:

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude>  (max.(+1)) 2 2
3

But if I remove the parenthesis I get a beast that I have no idea what its type signature mean any more

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude> :t max.(+1) 2 2
max.(+1) 2 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

How did removal of parenthesis changed the meaning?      How do you interpret the type:  "(Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b"?

Thanks

--
Daryoush

Weblog:  http://onfp.blogspot.com/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

--
Daryoush

Weblog:  http://onfp.blogspot.com/

```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
16 Nov 09:00 2012

### Re: need help with understanding expression

Yes, same problem, and again I have no idea how to read the type

Prelude> :t max. 3 2
max. 3 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

What does the type mean in plain english?

Daryoush

On Thu, Nov 15, 2012 at 11:56 PM, Ramana Kumar wrote:
Another experiment may be revealing:

:t 3 2

On Fri, Nov 16, 2012 at 7:46 AM, Daryoush Mehrtash wrote:
I see the point with :t (.)  that

max.(+1) 2 2

is the same as

max. 3 2

Which is not what I want.

But I have no idea what the type signature of this expression mean now

Prelude> :t max. 3 2
max. 3 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

Any idea?

Daryoush

On Thu, Nov 15, 2012 at 11:19 PM, Ramana Kumar wrote:
Hi Daryoush,

I recommend you try these experiments first, and then reply back if you're still confused.

:t max

:t (+1)

:t max . (+1)

:t (+1) 2

:t (.)

On Fri, Nov 16, 2012 at 7:10 AM, Daryoush Mehrtash wrote:
I am having hard time understanding how removing the  outer parenthesis in

(max.(+1)) 2 2

to

max.(+1) 2 2

changes the meaning of expression.

My expectation was that "max.(+1) takes two numbers and returns the max as defined in the type:

:t max.(+1)
max.(+1) :: (Ord b, Num b) => b -> b -> b

With parenthesis it does what I expect it to:

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude>  (max.(+1)) 2 2
3

But if I remove the parenthesis I get a beast that I have no idea what its type signature mean any more

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude> :t max.(+1) 2 2
max.(+1) 2 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

How did removal of parenthesis changed the meaning?      How do you interpret the type:  "(Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b"?

Thanks

--
Daryoush

Weblog:  http://onfp.blogspot.com/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

--
Daryoush

Weblog:  http://onfp.blogspot.com/

--
Daryoush

Weblog:  http://onfp.blogspot.com/
```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
16 Nov 09:00 2012

### Re: need help with understanding expression

Sorry wrong paste

Prelude> :t 3 2
3 2 :: (Num a, Num (a -> t)) => t

What does the type mean in plain english?

Daryoush

On Fri, Nov 16, 2012 at 12:00 AM, Daryoush Mehrtash wrote:
Yes, same problem, and again I have no idea how to read the type

Prelude> :t max. 3 2
max. 3 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

What does the type mean in plain english?

Daryoush

On Thu, Nov 15, 2012 at 11:56 PM, Ramana Kumar wrote:
Another experiment may be revealing:

:t 3 2

On Fri, Nov 16, 2012 at 7:46 AM, Daryoush Mehrtash wrote:
I see the point with :t (.)  that

max.(+1) 2 2

is the same as

max. 3 2

Which is not what I want.

But I have no idea what the type signature of this expression mean now

Prelude> :t max. 3 2
max. 3 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

Any idea?

Daryoush

On Thu, Nov 15, 2012 at 11:19 PM, Ramana Kumar wrote:
Hi Daryoush,

I recommend you try these experiments first, and then reply back if you're still confused.

:t max

:t (+1)

:t max . (+1)

:t (+1) 2

:t (.)

On Fri, Nov 16, 2012 at 7:10 AM, Daryoush Mehrtash wrote:
I am having hard time understanding how removing the  outer parenthesis in

(max.(+1)) 2 2

to

max.(+1) 2 2

changes the meaning of expression.

My expectation was that "max.(+1) takes two numbers and returns the max as defined in the type:

:t max.(+1)
max.(+1) :: (Ord b, Num b) => b -> b -> b

With parenthesis it does what I expect it to:

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude>  (max.(+1)) 2 2
3

But if I remove the parenthesis I get a beast that I have no idea what its type signature mean any more

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude> :t max.(+1) 2 2
max.(+1) 2 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

How did removal of parenthesis changed the meaning?      How do you interpret the type:  "(Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b"?

Thanks

--
Daryoush

Weblog:  http://onfp.blogspot.com/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

--
Daryoush

Weblog:  http://onfp.blogspot.com/

--
Daryoush

Weblog:  http://onfp.blogspot.com/

--
Daryoush

Weblog:  http://onfp.blogspot.com/
```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
16 Nov 09:07 2012

### Re: need help with understanding expression

On Fri, Nov 16, 2012 at 8:00 AM, Daryoush Mehrtash wrote:
Sorry wrong paste

Prelude> :t 3 2
3 2 :: (Num a, Num (a -> t)) => t

It means that 2 has type a (which must be in the Num class), 3 has type (a -> t) (which also must be in the Num class), and the type of (3 2) is therefore t.
When you apply one expression to another, the first must have function type, and the second must have the type of the domain of the function, hence the a -> t and a.
Furthermore, the numeric literals are always interpreted as being in the Num class.
I haven't been able to find any good introduction to numeric literals and the Num class with quick search, so if anyone else on list can point us to one (if it exists) that would be great.

What does the type mean in plain english?

Daryoush

On Fri, Nov 16, 2012 at 12:00 AM, Daryoush Mehrtash wrote:
Yes, same problem, and again I have no idea how to read the type

Prelude> :t max. 3 2
max. 3 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

What does the type mean in plain english?

Daryoush

On Thu, Nov 15, 2012 at 11:56 PM, Ramana Kumar wrote:
Another experiment may be revealing:

:t 3 2

On Fri, Nov 16, 2012 at 7:46 AM, Daryoush Mehrtash wrote:
I see the point with :t (.)  that

max.(+1) 2 2

is the same as

max. 3 2

Which is not what I want.

But I have no idea what the type signature of this expression mean now

Prelude> :t max. 3 2
max. 3 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

Any idea?

Daryoush

On Thu, Nov 15, 2012 at 11:19 PM, Ramana Kumar wrote:
Hi Daryoush,

I recommend you try these experiments first, and then reply back if you're still confused.

:t max

:t (+1)

:t max . (+1)

:t (+1) 2

:t (.)

On Fri, Nov 16, 2012 at 7:10 AM, Daryoush Mehrtash wrote:
I am having hard time understanding how removing the  outer parenthesis in

(max.(+1)) 2 2

to

max.(+1) 2 2

changes the meaning of expression.

My expectation was that "max.(+1) takes two numbers and returns the max as defined in the type:

:t max.(+1)
max.(+1) :: (Ord b, Num b) => b -> b -> b

With parenthesis it does what I expect it to:

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude>  (max.(+1)) 2 2
3

But if I remove the parenthesis I get a beast that I have no idea what its type signature mean any more

Prelude> :t (max.(+1)) 2 2
(max.(+1)) 2 2 :: (Ord b, Num b) => b
Prelude> :t max.(+1) 2 2
max.(+1) 2 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b

How did removal of parenthesis changed the meaning?      How do you interpret the type:  "(Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b"?

Thanks

--
Daryoush

Weblog:  http://onfp.blogspot.com/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

--
Daryoush

Weblog:  http://onfp.blogspot.com/

--
Daryoush

Weblog:  http://onfp.blogspot.com/

--
Daryoush

Weblog:  http://onfp.blogspot.com/

```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
16 Nov 09:57 2012

### Re: need help with understanding expression

Hi Daryoush,

Prelude> :t 3 2
3 2 :: (Num a, Num (a -> t)) => t

What does the type mean in plain english?

It's important to remember that numeric literals are polymorphic. That is, 3 :: Num a => a. They do not have monomorphic types such as Int or Integer.

In the above, GHCi is inferring the principal type of 3 applied to 2. Since 3 is in the position of function application, it should have a function type, e.g. a -> t. And 2 is the argument to 3, so it has the type 'a'. But there must be Num constraints on these types, and that's what the context (Num a, Num (a -> t)) is telling you. Num (a -> t) is a strange constraint but so is applying 3 to 2. Whenever you see a Num constraint on a function type, it probably means you're doing something wrong.

You might find the (brief) description of typing numeric literals in the language definition helpful:

Also, in response to your initial query...

I am having hard time understanding how removing the  outer parenthesis in
(max.(+1)) 2 2
to
max.(+1) 2 2

Keep in mind the precedence of the function composition operator (.) here:

Prelude> :i (.)
(.) :: (b -> c) -> (a -> b) -> a -> c -- Defined in GHC.Base
infixr 9 .

Function application is infixl 10, so even though max . (+1) :: (Num b, Ord b) => b -> b -> b, when you do max . (+1) 2, the application of (+1) to 2 binds more tightly than (.).

A common idiom for removing parentheses with a sequence of compositions is to use (\$):

Prelude> :i (\$)
(\$) :: (a -> b) -> a -> b -- Defined in GHC.Base
infixr 0 \$

Note that it has the lowest possible precedence. So, you often see the composition of functions as f . g . h \$ arg. But this doesn't work well for (curried) functions with 2 arguments. So, in your case, I'd guess the parentheses is simplest idiomatic solution. Though, I think I'd prefer max (succ 2) 2.

Regards,
Sean
```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
17 Nov 08:19 2012

### Re: need help with understanding expression

Let's see tthis:

Prelude> :t 3 "a"
3 "a" :: (Num ([Char] -> t)) => t

No complaint from GHC; but now see this:

Prelude> :t  "a" 3

<interactive>:1:0:
Couldn't match expected type `t1 -> t'
against inferred type `[Char]'
In the expression: "a" 3

Why does it not fail for  (:t 3 "a") but does fail for (:t  "a" 3)?

In the second case, why the GHC doesn't give something like?
([Char] (a -> t), Num a) => t

In other words, how the first one does make "sense" (however strange the "sense" may seem) to GHC while the second one doesn't?

Now let's consider the evaluation scenario:

Prelude>  3 2

<interactive>:1:0:
No instance for (Num (t -> t1))
arising from the literal `3' at <interactive>:1:0-2
Possible fix: add an instance declaration for (Num (t -> t1))
In the expression: 3 2
In the definition of `it': it = 3 2

Note, how the GHC suggests us this "strange constraint" as a possible fix BUT see this:
Prelude>  "a" 2

<interactive>:1:0:
Couldn't match expected type `t1 -> t'
against inferred type `[Char]'
In the expression: "a" 2
In the definition of `it': it = "a" 2

In this case the GHC doesn't even allow us to add any "possible fix".

-Damodar

On Fri, Nov 16, 2012 at 2:27 PM, Sean Leather wrote:
Hi Daryoush,

Prelude> :t 3 2
3 2 :: (Num a, Num (a -> t)) => t

What does the type mean in plain english?

It's important to remember that numeric literals are polymorphic. That is, 3 :: Num a => a. They do not have monomorphic types such as Int or Integer.

In the above, GHCi is inferring the principal type of 3 applied to 2. Since 3 is in the position of function application, it should have a function type, e.g. a -> t. And 2 is the argument to 3, so it has the type 'a'. But there must be Num constraints on these types, and that's what the context (Num a, Num (a -> t)) is telling you. Num (a -> t) is a strange constraint but so is applying 3 to 2. Whenever you see a Num constraint on a function type, it probably means you're doing something wrong.

You might find the (brief) description of typing numeric literals in the language definition helpful:

Also, in response to your initial query...

I am having hard time understanding how removing the  outer parenthesis in
(max.(+1)) 2 2
to
max.(+1) 2 2

Keep in mind the precedence of the function composition operator (.) here:

Prelude> :i (.)
(.) :: (b -> c) -> (a -> b) -> a -> c -- Defined in GHC.Base
infixr 9 .

Function application is infixl 10, so even though max . (+1) :: (Num b, Ord b) => b -> b -> b, when you do max . (+1) 2, the application of (+1) to 2 binds more tightly than (.).

A common idiom for removing parentheses with a sequence of compositions is to use (\$):

Prelude> :i (\$)
(\$) :: (a -> b) -> a -> b -- Defined in GHC.Base
infixr 0 \$

Note that it has the lowest possible precedence. So, you often see the composition of functions as f . g . h \$ arg. But this doesn't work well for (curried) functions with 2 arguments. So, in your case, I'd guess the parentheses is simplest idiomatic solution. Though, I think I'd prefer max (succ 2) 2.

Regards,
Sean

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

--
Thanks and regards,
-Damodar Kulkarni

```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
17 Nov 09:17 2012

### Re: need help with understanding expression

Отправлено с iPhone

17.11.2012, в 11:19, damodar kulkarni <kdamodar2000 <at> gmail.com> написал(а):

In the second case, why the GHC doesn't give something like?
([Char] (a -> t), Num a) => t

Because "Num" is a class of types, while "String" is a type.

In other words, in the expression 3 "a" ghc doesn't know, what type 3 belongs to, it just knows that it should be of class Num. In particular, it could be of type "String -> t" for some t, ghc wouldn't go over all possible types to see that there is no such instance of "Num".

On the other hand, in "a" 3 it knows exactly what type "a" is, strings are always of one type, "String" (which is an alias for [Char]). You can enable OverloadedStrings extension, which makes string literals polymorphic; then you'll have your type, which would be something like "(IsString (a -> b), Num a) => b".

Now let's consider the evaluation scenario:

Prelude>  3 2

<interactive>:1:0:
No instance for (Num (t -> t1))
arising from the literal `3' at <interactive>:1:0-2
Possible fix: add an instance declaration for (Num (t -> t1))
In the expression: 3 2
In the definition of `it': it = 3 2

Note, how the GHC suggests us this "strange constraint" as a possible fix BUT see this:
Prelude>  "a" 2

<interactive>:1:0:
Couldn't match expected type `t1 -> t'
against inferred type `[Char]'
In the expression: "a" 2
In the definition of `it': it = "a" 2

In this case the GHC doesn't even allow us to add any "possible fix".

Same thing. "String" is NOT a functional type, and it would never be, while it's possible (and sometimes reasonable) to have a functional type of class "Num". Enable OverloadedStrings, and you'll see your desired "possible fix".
```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
18 Nov 02:57 2012

### Re: need help with understanding expression

```On 12-11-17 02:19 AM, damodar kulkarni wrote:
> Let's see tthis:
> Prelude> :t 3 "a"
> 3 "a" :: (Num ([Char] -> t)) => t
>
> No complaint from GHC; but now see this:
>
> Prelude> :t  "a" 3
>
> <interactive>:1:0:
>      Couldn't match expected type `t1 -> t'
>             against inferred type `[Char]'
>      In the expression: "a" 3
>
> Why does it not fail for  (:t 3 "a") but does fail for (:t  "a" 3)?

3 is polymorphic, "a" is monomorphic (exactly [Char]).

To make "a" polymorphic, turn on OverloadedStrings:

:set -XOverloadedStrings
:type "a"

"a" :: Data.String.IsString a => a

:type "a" 3

"a" 3 :: (Num a, Data.String.IsString (a -> t)) => t

Success!

This is clearly depravity.
```
25 Nov 04:19 2012

### Re: need help with understanding expression

Hi,
Thanks for the clarification.

This is clearly depravity.

I am confused, in what sense this is depravity?

Damodar

On Sun, Nov 18, 2012 at 7:27 AM, Albert Y. C. Lai wrote:
On 12-11-17 02:19 AM, damodar kulkarni wrote:
Let's see tthis:
Prelude> :t 3 "a"
3 "a" :: (Num ([Char] -> t)) => t

No complaint from GHC; but now see this:

Prelude> :t  "a" 3

<interactive>:1:0:
Couldn't match expected type `t1 -> t'
against inferred type `[Char]'
In the expression: "a" 3

Why does it not fail for  (:t 3 "a") but does fail for (:t  "a" 3)?

3 is polymorphic, "a" is monomorphic (exactly [Char]).

To make "a" polymorphic, turn on OverloadedStrings:

:set -XOverloadedStrings
:type "a"

"a" :: Data.String.IsString a => a

:type "a" 3

"a" 3 :: (Num a, Data.String.IsString (a -> t)) => t

Success!

This is clearly depravity.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

```_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
```
16 Nov 20:53 2012

### Re: need help with understanding expression

```On 12-11-16 02:10 AM, Daryoush Mehrtash wrote:
> I am having hard time understanding how removing the  outer parenthesis in
>
> (max.(+1)) 2 2
>
> to
>
> max.(+1) 2 2
>
> changes the meaning of expression.

I recommend http://bm380.user.srcf.net/prettyparsetree.cgi for
discovering the correct parse.

Specifically,

max.(+1) 2 2
=  { use uniform spacing to un-presume }
max . (+1) 2 2
=  { . is lower than application }
max . ((+1) 2 2)

etc.
```

Gmane