[Haskell-cafe] Problem with type signature in local function

2004-12-24 Thread Christian Hofer
Hi,
in order to understand the reason for strange compiler error messages, 
I often find it convenient to add type signatures to every function. 
But sometimes this seems to be impossible when using type variables.

I try to give a very easy example:
add :: Num a = a - a - a
add n1 n2 = addToN1 n2
   where addToN1 :: Num a = a - a
 addToN1 number = n1 + number
ghc says Inferred type is less polymorphic than expected, and justly 
so, because the type variable a in addToN1 must of course be the same 
as in add. Is there a way to specify this?

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


Re: [Haskell-cafe] Problem with type signature in local function

2004-12-24 Thread Ralf Laemmel
Timely question. :-)
GHC supports lexically scoped type variables.
And this support has just been _extended_ to be readily useful for you
(see discussion on the ghc list just a few days back).
With GHC CVS HEAD the following program works fine.
(Note that I removed the inner Num constraint.)
{-# OPTIONS -fglasgow-exts #-}
add :: Num a = a - a - a
add n1 n2 = addToN1 n2
  where addToN1 :: a - a
addToN1 number = n1 + number
... even though I would not claim that this is a really strong example
of lexically scoped variables, but you probably just simplied a real 
code example.
And most of my recent code I use lexically scoped type variables
extensively. They are great.

(In principle, one does not need them at the cost of encoding. Using 
asTypeOf and friends ...)

Merry Xmas,
Ralf
Christian Hofer wrote:
Hi,
in order to understand the reason for strange compiler error messages, 
I often find it convenient to add type signatures to every function. 
But sometimes this seems to be impossible when using type variables.

I try to give a very easy example:
add :: Num a = a - a - a
add n1 n2 = addToN1 n2
   where addToN1 :: Num a = a - a
 addToN1 number = n1 + number
ghc says Inferred type is less polymorphic than expected, and justly 
so, because the type variable a in addToN1 must of course be the 
same as in add. Is there a way to specify this?

Regards,
Chris
___
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] Problem with type signature in local function

2004-12-24 Thread Arthur Baars
You could also do it with the current implementation of scoped type 
variables. So you don't need to compile the CVS HEAD version. Note that 
you need the pattern (n1::a) and/or (n2::a) to introduce the scoped 
type variable, which was not necessary in Ralf's solution.

{-# OPTIONS -fglasgow-exts #-}
add :: Num a = a - a - a
add (n1::a) n2 = addToN1 n2
   where addToN1 :: a - a
 addToN1 number = n1 + number
Cheers,
Arthur
On 24-dec-04, at 13:04, Ralf Laemmel wrote:
Timely question. :-)
GHC supports lexically scoped type variables.
And this support has just been _extended_ to be readily useful for you
(see discussion on the ghc list just a few days back).
With GHC CVS HEAD the following program works fine.
(Note that I removed the inner Num constraint.)
{-# OPTIONS -fglasgow-exts #-}
add :: Num a = a - a - a
add n1 n2 = addToN1 n2
  where addToN1 :: a - a
addToN1 number = n1 + number
... even though I would not claim that this is a really strong example
of lexically scoped variables, but you probably just simplied a real 
code example.
And most of my recent code I use lexically scoped type variables
extensively. They are great.

(In principle, one does not need them at the cost of encoding. Using 
asTypeOf and friends ...)

Merry Xmas,
Ralf
Christian Hofer wrote:
Hi,
in order to understand the reason for strange compiler error 
messages, I often find it convenient to add type signatures to every 
function. But sometimes this seems to be impossible when using type 
variables.

I try to give a very easy example:
add :: Num a = a - a - a
add n1 n2 = addToN1 n2
   where addToN1 :: Num a = a - a
 addToN1 number = n1 + number
ghc says Inferred type is less polymorphic than expected, and 
justly so, because the type variable a in addToN1 must of course be 
the same as in add. Is there a way to specify this?

Regards,
Chris
___
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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Ignorant begginer question

2004-12-24 Thread John Goerzen
On 2004-12-23, Stefan Holdermans [EMAIL PROTECTED] wrote:
 Your problem right now is that the type Complex takes (needs) a type 
 argument. Its definitions is (module strictness flags):

data Complex a = a :+ a

What does the :+ mean here?


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


[Haskell-cafe] Re: ANN: MissingH 0.8.0 (Festive Lambda)

2004-12-24 Thread John Goerzen
On 2004-12-24, John Goerzen [EMAIL PROTECTED] wrote:
  * Virtualized I/O system
Use familiar functions to work on not just Handles but all sorts of
other types, including in-memory buffers. (HVIO module)

I should comment on this...  I went with basically what I originally
asked about here.  Not because I think my idea is better, but because:

1) It was most compatible with existing Haskell code,

2) I know how to implement it in a portable manner :-)

If you are curious, there are haddock files at
http://quux.org/devel/missingh/html/index.html

-- John

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


Re: [Haskell-cafe] Problem with type signature in local function

2004-12-24 Thread Christian Hofer
Thank you all for your answers!
I indeed do not want to use CVS HEAD, but it's nice to know that there 
will be a better solution some time. Until then I will write s.th. like

loop (residual :: MutableGraph state node weight) flow absValue = ...
which is completely sufficient for my purposes (implementing my Java 
homework in the imperative language of my choice)...

Merry christmas,
Chris
Am 24.12.2004 um 14:33 schrieb Arthur Baars:
You could also do it with the current implementation of scoped type 
variables. So you don't need to compile the CVS HEAD version. Note 
that you need the pattern (n1::a) and/or (n2::a) to introduce the 
scoped type variable, which was not necessary in Ralf's solution.

{-# OPTIONS -fglasgow-exts #-}
add :: Num a = a - a - a
add (n1::a) n2 = addToN1 n2
   where addToN1 :: a - a
 addToN1 number = n1 + number
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Ignorant begginer question

2004-12-24 Thread Jules Bean
On 24 Dec 2004, at 14:53, John Goerzen wrote:
On 2004-12-23, Stefan Holdermans [EMAIL PROTECTED] wrote:
Your problem right now is that the type Complex takes (needs) a type
argument. Its definitions is (module strictness flags):
   data Complex a = a :+ a
What does the :+ mean here?
It's a data constructor, written infix. Infix constructors all begin 
with ':', I think.

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


Re: [Haskell-cafe] Re: Ignorant begginer question

2004-12-24 Thread Stefan Holdermans
Jules,
It's a data constructor, written infix. Infix constructors all begin 
with ':', I think.
That's correct.
Regards,
Stefan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Ignorant begginer question

2004-12-24 Thread Tomasz Zielonka
On Fri, Dec 24, 2004 at 03:14:34PM +, Jules Bean wrote:
 It's a data constructor, written infix. Infix constructors all begin 
 with ':', I think.

Yes, but you can also use prefix, alphanumeric constructors as infix
by placing them in backticks. This can be nice sometimes:

data Expr = ...
  | Expr `In` [Expr]
  | Expr `And` Expr
  | Expr `Or` Expr
  ...

case e of
e1 `In` es - ...

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