Different behavior of GHC 6.10.1 and Hugs (Sep 2006)

2010-04-03 Thread Vladimir Reshetnikov
Hi list,

GHC 6.10.1:

Prelude :t let f x y = return x == return y in f
let f x y = return x == return y in f :: (Eq (m a), Monad m) = a - a -
Bool

Hugs (Sep 2006):

Hugs :t let f x y = return x == return y in f
ERROR - Ambiguous type signature in inferred type
*** ambiguous type : (Eq (a b), Monad a) = b - b - Bool
*** assigned to: f

Who is right?

--
Thanks
Vladimir
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


[Haskell-cafe] Different behavior of GHC 6.10.1 and Hugs (Sep 2006)

2010-04-03 Thread Vladimir Reshetnikov
Hi list,

GHC 6.10.1:

Prelude :t let f x y = return x == return y in f
let f x y = return x == return y in f :: (Eq (m a), Monad m) = a - a -
Bool

Hugs (Sep 2006):

Hugs :t let f x y = return x == return y in f
ERROR - Ambiguous type signature in inferred type
*** ambiguous type : (Eq (a b), Monad a) = b - b - Bool
*** assigned to: f

Who is right?

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


[Haskell-cafe] Why there is not standard Monoid instance for ZipList a?

2009-10-16 Thread Vladimir Reshetnikov
I find the following instance very convenient:

import Data.Monoid
import Control.Applicative
instance Monoid a = Monoid (ZipList a) where
  mempty = pure mempty
  mappend = liftA2 mappend


Any reason why it is not in the standard library?

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


Re: [Haskell-cafe] Monotype error

2009-10-15 Thread Vladimir Reshetnikov
See our previous discussion on this topic here:
http://www.nabble.com/Fwd:-Unification-for-rank-N-types-td23942179.html

Thanks,
Vladimir

On Wed, Oct 14, 2009 at 10:35 PM, Martijn van Steenbergen 
mart...@van.steenbergen.nl wrote:

 Dear café,

  {-# LANGUAGE Rank2Types #-}
 {-# LANGUAGE ImpredicativeTypes #-}

 type Void = forall a. a

 newtype Mono a = Mono { runMono :: [Void] }

 beep :: Mono a - Mono a
 beep (Mono vs) = Mono (map undefined vs)


 Compiling this with GHC results in:

  Monotype.hs:9:28:
Cannot match a monotype with `Void'
  Expected type: Void
  Inferred type: a


 What does this error mean and why does the code not compile?

 Thanks!

 Martijn.
 ___
 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


List comprehensions and impredicative rank-N types

2009-06-11 Thread Vladimir Reshetnikov
Hi,

Consider the following definitions:

---
{-# LANGUAGE RankNTypes, ImpredicativeTypes #-}

foo :: [forall a. [a] - [a]]
foo = [reverse]

bar :: [a - b] - a - b
bar fs = head fs
---

According to the Haskell Report, [f | f - foo] translates to (let ok
f = [f]; ok _ = [] in concatMap ok foo), right?

So, I wonder why (bar [f | f - foo]) typechecks, but (bar (let ok f =
[f]; ok _ = [] in concatMap ok foo)) and (bar foo) do not typecheck?

Thanks,
Vladimir
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


[Haskell-cafe] List comprehensions and impredicative rank-N types

2009-06-11 Thread Vladimir Reshetnikov
Hi,

Consider the following definitions:

---
{-# LANGUAGE RankNTypes, ImpredicativeTypes #-}

foo :: [forall a. [a] - [a]]
foo = [reverse]

bar :: [a - b] - a - b
bar fs = head fs
---

According to the Haskell Report, [f | f - foo] translates to (let ok
f = [f]; ok _ = [] in concatMap ok foo), right?

So, I wonder why (bar [f | f - foo]) typechecks, but (bar (let ok f =
[f]; ok _ = [] in concatMap ok foo)) and (bar foo) do not typecheck?

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


Fwd: Unification for rank-N types

2009-06-09 Thread Vladimir Reshetnikov
Forwarding to GH list.

-- Forwarded message --
From: Vladimir Reshetnikov v.reshetni...@gmail.com
Date: Tue, 9 Jun 2009 16:51:59 +0500
Subject: Re: Unification for rank-N types
To: haskell-cafe haskell-c...@haskell.org

One more example:

This does not type-check:
---
{-# LANGUAGE RankNTypes, ImpredicativeTypes #-}

f :: [forall a. t a - t a] - t b - t b
f = foldr (.) id
---

Couldn't match expected type `forall a. f a - f a'
   against inferred type `b - c'
In the first argument of `foldr', namely `(.)'

But this, very similar, does type-check:
---
{-# LANGUAGE RankNTypes, ImpredicativeTypes #-}

f :: [forall a. t a - t a] - t b - t b
f = foldr (\g - (.) g) id
---

What is the reason for this?

Thanks,
Vladimir


On 6/9/09, Vladimir Reshetnikov v.reshetni...@gmail.com wrote:
 Hi,

 I have the following code:
 ---
 {-# LANGUAGE RankNTypes #-}

 f :: ((forall a. a - a) - b) - b
 f x = x id

 g :: (forall c. Eq c = [c] - [c]) - ([Bool],[Int])
 g y = (y [True], y [1])

 h :: ([Bool],[Int])
 h = f g
 ---

 GHC rejects it:
 Couldn't match expected type `forall a. a - a'
against inferred type `forall c. (Eq c) = [c] - [c]'
   Expected type: forall a. a - a
   Inferred type: forall c. (Eq c) = [c] - [c]
 In the first argument of `f', namely `g'
 In the expression: f g

 But, intuitively, this code is type-safe, and actually I can convince
 the typechecker in it with the following workaround:
 ---
 h :: ([Bool],[Int])
 h = let g' = (\(x :: forall a. a - a) - g x) in f g'
 ---

 So, is the current behavior of GHC correct ot it is a bug?
 How unification for rank-N types should proceed?

 Thanks,
 Vladimir

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


[Haskell-cafe] Unification for rank-N types

2009-06-09 Thread Vladimir Reshetnikov
Hi,

I have the following code:
---
{-# LANGUAGE RankNTypes #-}

f :: ((forall a. a - a) - b) - b
f x = x id

g :: (forall c. Eq c = [c] - [c]) - ([Bool],[Int])
g y = (y [True], y [1])

h :: ([Bool],[Int])
h = f g
---

GHC rejects it:
Couldn't match expected type `forall a. a - a'
   against inferred type `forall c. (Eq c) = [c] - [c]'
  Expected type: forall a. a - a
  Inferred type: forall c. (Eq c) = [c] - [c]
In the first argument of `f', namely `g'
In the expression: f g

But, intuitively, this code is type-safe, and actually I can convince
the typechecker in it with the following workaround:
---
h :: ([Bool],[Int])
h = let g' = (\(x :: forall a. a - a) - g x) in f g'
---

So, is the current behavior of GHC correct ot it is a bug?
How unification for rank-N types should proceed?

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


[Haskell-cafe] Re: Unification for rank-N types

2009-06-09 Thread Vladimir Reshetnikov
One more example:

This does not type-check:
---
{-# LANGUAGE RankNTypes, ImpredicativeTypes #-}

f :: [forall a. t a - t a] - t b - t b
f = foldr (.) id
---

Couldn't match expected type `forall a. f a - f a'
   against inferred type `b - c'
In the first argument of `foldr', namely `(.)'

But this, very similar, does type-check:
---
{-# LANGUAGE RankNTypes, ImpredicativeTypes #-}

f :: [forall a. t a - t a] - t b - t b
f = foldr (\g - (.) g) id
---

What is the reason for this?

Thanks,
Vladimir


On 6/9/09, Vladimir Reshetnikov v.reshetni...@gmail.com wrote:
 Hi,

 I have the following code:
 ---
 {-# LANGUAGE RankNTypes #-}

 f :: ((forall a. a - a) - b) - b
 f x = x id

 g :: (forall c. Eq c = [c] - [c]) - ([Bool],[Int])
 g y = (y [True], y [1])

 h :: ([Bool],[Int])
 h = f g
 ---

 GHC rejects it:
 Couldn't match expected type `forall a. a - a'
against inferred type `forall c. (Eq c) = [c] - [c]'
   Expected type: forall a. a - a
   Inferred type: forall c. (Eq c) = [c] - [c]
 In the first argument of `f', namely `g'
 In the expression: f g

 But, intuitively, this code is type-safe, and actually I can convince
 the typechecker in it with the following workaround:
 ---
 h :: ([Bool],[Int])
 h = let g' = (\(x :: forall a. a - a) - g x) in f g'
 ---

 So, is the current behavior of GHC correct ot it is a bug?
 How unification for rank-N types should proceed?

 Thanks,
 Vladimir

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


Re: [Haskell-cafe] Question on rank-N polymorphism

2009-06-07 Thread Vladimir Reshetnikov
Hi Zsolt,

fs :: (((a, a) - a) - t) - (t, t)
fs g = (g fst, g snd)
examples = (fs fmap, fs liftA, fs liftM, fs id, fs ($(1,2)), fs
((,)id), fs (:[]), fs repeat)

No instance for (Num [Char])
  arising from the literal `1' at M.hs:6:54
Possible fix: add an instance declaration for (Num [Char])
In the expression: 1
In the second argument of `($)', namely `(1, 2)'
In the first argument of `fs', namely `($ (1, 2))'

Anyways, this signature is not what intended. I want it to work for
all tuples, regardless of their element types.

Thanks
Vladimir

On 6/7/09, Zsolt Dollenstein zsol.z...@gmail.com wrote:
 On Sun, Jun 7, 2009 at 9:17 AM, Vladimir
 Reshetnikovv.reshetni...@gmail.com wrote:
 Hi Zsolt,

 It does not compiles with GHC without type annotations.

 It does with mine: The Glorious Glasgow Haskell Compilation System, version
 6.10.2

 Anyway, try this: fs :: (((a, a) - a) - t) - (t, t)


 Thanks,
 Vladimir

 On 6/7/09, Zsolt Dollenstein zsol.z...@gmail.com wrote:
 Hi Vladimir,

 On Sun, Jun 7, 2009 at 12:06 AM, Vladimir
 Reshetnikovv.reshetni...@gmail.com wrote:
 Hi,

 I have the following code:

 
 fs g = (g fst, g snd)
 examples = (fs fmap, fs liftA, fs liftM, fs id, fs ($(1,2)), fs
 ((,)id), fs (:[]), fs repeat)
 

 The idea is that fs accepts a polymorphic function as its argument.
 What type signature can I specify for f in order to compile this code?

 Have you tried putting the above into ghci for example, then asking for
 :t
 fs?
 Or am I misunderstanding your point?

 Cheers,
 Zsolt

 If it is not possible in Haskell, is there another language with
 static typing which allows this?

 Thanks,
 Vladimir
 ___
 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


[Haskell-cafe] Question on rank-N polymorphism

2009-06-06 Thread Vladimir Reshetnikov
Hi,

I have the following code:


fs g = (g fst, g snd)
examples = (fs fmap, fs liftA, fs liftM, fs id, fs ($(1,2)), fs
((,)id), fs (:[]), fs repeat)


The idea is that fs accepts a polymorphic function as its argument.
What type signature can I specify for f in order to compile this code?
If it is not possible in Haskell, is there another language with
static typing which allows this?

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


[Haskell-cafe] Trouble with types

2009-06-01 Thread Vladimir Reshetnikov
Hi,

I tried this code:

---
f, g :: a - a
(f, g) = (id, id)
---

Hugs: OK

GHC:
Couldn't match expected type `forall a. a - a'
   against inferred type `a - a'
In the expression: id
In the expression: (id, id)
In a pattern binding: (f, g) = (id, id)

What does mean this error message?
And what of them (Hugs, GHC) is correct?

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


Re: [Haskell-cafe] Trouble with types

2009-06-01 Thread Vladimir Reshetnikov
Hi Daniel,

Could you please explain what does mean 'monomorphic' in this context?
I thought that all type variables in Haskell are implicitly
universally quantified, so (a - a) is the same type as (forall a. a
- a)

Thank you,
Vladimir

On 6/1/09, Daniel Fischer daniel.is.fisc...@web.de wrote:
 Am Montag 01 Juni 2009 14:44:37 schrieb Vladimir Reshetnikov:
 Hi,

 I tried this code:

 ---
 f, g :: a - a
 (f, g) = (id, id)
 ---

 Hugs: OK

 GHC:
 Couldn't match expected type `forall a. a - a'
against inferred type `a - a'
 In the expression: id
 In the expression: (id, id)
 In a pattern binding: (f, g) = (id, id)

 What does mean this error message?
 And what of them (Hugs, GHC) is correct?

 http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs-and-infelicities.html
 Section 12.1.1.4, Declarations and bindings

 GHC's typechecker makes all pattern bindings monomorphic by default; this
 behaviour can be
 disabled with -XNoMonoPatBinds. See Section 7.1, “Language options”.

 Hugs is correct, it's a known infelicity in GHC which can be disabled.

 Thanks
 Vladimir


 ___
 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


[Haskell-cafe] Question on kind inference

2009-05-31 Thread Vladimir Reshetnikov
Hi,

Consider this Haskell code:

---
class A a where
  foo :: a b

class B a

class (A a, B a) = C a
---

GHC compiles it without errors, but Hugs rejects it: Illegal type in
class constraint.
What is the correct behavior, and which part of the haskell 98 report
explains this?

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


[Haskell-cafe] Which type variables are allowed in a context?

2009-05-31 Thread Vladimir Reshetnikov
Hi,

Consider this (a bit pathological) Haskell code:

--
class A a where
  foo :: A (b d) = a (c b)
--

GHC compiles it successfully, but Hugs rejects it:

Ambiguous type signature in class declaration
*** ambiguous type : (A a, A (b c)) = a (d b)
*** assigned to: foo

What is the correct behavior, and which part of the haskell 98 report
explains this?

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


[Haskell-cafe] (no subject)

2009-05-31 Thread Vladimir Reshetnikov
Hi,

Seems that Haskell allows to specify dummy type variables in a
declaration of a type synonym, which do not appear in its right-hand
side. This can lead to interesting effects, which appears differently
in GHC and Hugs. I would like to know, what behavior is correct
according to the haskell 98 report.

1)
--
type F a = Int

class A a where
  foo :: A b = a (F b)
--

GHC - OK
Hugs - Illegal type F b in constructor application

2)
--
type F a = Int

class A a where
  foo :: F a

instance A Bool where
  foo = 1

instance A Char where
  foo = 2

xs = [foo :: F Bool, foo :: F Char]
--

GHC:

M.hs:14:6:
Ambiguous type variable `a' in the constraint:
  `A a' arising from a use of `foo' at M.hs:14:6-8
Probable fix: add a type signature that fixes these type variable(s)

M.hs:14:21:
Ambiguous type variable `a1' in the constraint:
  `A a1' arising from a use of `foo' at M.hs:14:21-23
Probable fix: add a type signature that fixes these type variable(s)

Hugs: [1,2]



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


[Haskell-cafe] GHCi vs. Hugs (record syntax)

2009-05-31 Thread Vladimir Reshetnikov
Hi,

I tried to evaluate this expression:

head[[]{}]

GHCi: []
Hugs: ERROR - Empty field list in update

What is the correct behavior?

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


[Haskell-cafe] Hugs vs. GHCi

2009-05-29 Thread Vladimir Reshetnikov
Hi,

The following expression evaluates to 1 in GHCi, but results in an
error in Hugs:

let f x = let g y = [x,y] in (g 1, g []) in 1

What is the correct behavior?

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


[Haskell-cafe] Strange behavior of float literals

2008-04-05 Thread Vladimir Reshetnikov
The float literal 1e-1 in
GHC evaluates to 1.0, and
1e-9 evaluates to 10.0.
Is it a bug, or a documented overflow behavior?

What it the correct place to submit bug reports concerning GHC?
-- 
Thank you,

Vladimir Reshetnikov (aka nikov),
Microsoft MVP
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe