Formatting function types

2002-11-18 Thread Lauri Alanko
Just a silly thing that's been nagging me. a very common way (at least
in the base libraries) of formatting function types seems to be this:

hPutBuf :: Handle   -- handle to write to
- Ptr a-- address of buffer
- Int  -- number of bytes of data in buffer
- IO ()

I remember when I first started learning Haskell, and these many-arrowed
functions seemed very strange to me: Okay, we give it a handle, and get
a pointer, and, um, from this we get an int, and from this an action?
Er?

The problem here is that the first parameter has a distinguished look
while the other parameters and the return value all look the same. I
think that a naive reader is inclined to assume that line breaks are
situated at major structural boundaries. Consider two different
interpretations of the structure of the type term:

  (((Handle   (Handle
  - Ptr a) -(Ptr a
  - Int)   -(Int
  - IO ()) - IO (

Which looks more natural?

The point of this rant is just this: the aforementioned multi-line
formatting style should only be used for left-associative infix
operators. For right-associative ones (such as the function arrow), the
One True Way is this:

Handle -
Ptr a -
Int -
IO ()

Nuff said.


Lauri Alanko
[EMAIL PROTECTED]

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



RE: Bug? [was: Implicit params]

2002-11-18 Thread Simon Peyton-Jones
Now fixed in the HEAD, and will be in 5.04.2

Thanks for pointing it out.

Simon

| -Original Message-
| From: Jorge Adriano [mailto:[EMAIL PROTECTED]]
| Sent: 14 November 2002 21:10
| To: Iavor S. Diatchki
| Cc: Haskell Cafe; [EMAIL PROTECTED]
| Subject: Bug? [was: Implicit params]
| 
| On Thursday 14 November 2002 18:47, Iavor S. Diatchki wrote:
|  hello,
| 
|   Well, actually you must be right since the pure field defines a
pure
|   (projection) function... Hmmm, ok, can someone explain this to me,
|  
|   data E s = E{
| refi :: STRef s Int,
| refc :: STRef s Char,
| m:: Int
|   }
|  
|   -- this is fine, obviously...
|   pure   :: E s - Int
|   pure e = m e
|  
|   -- but this is not...
|   pure2 :: (?e :: E s) = Int
|   pure2 = m (?e)
|  
|   Why exactly isn't this allowed? What is the workaround?
|   Error msg:
|  

|   Ambiguous constraint `?e :: E s'
|   At least one of the forall'd type variables mentioned by
the
|   constraint
|   must be reachable from the type after the '='
|   In the type: forall s. (?e :: E s) = Int
|   While checking the type signature for `pure2'
|   Failed, modules loaded: none.
|  

-
|  -
| 
|  this seems like a bug in GHC.   Hugs is happy with it.  The s in
the
|  pure2 signature is not ambiguous because it is determined when you
give
|  the value of the implicit parameter.  in fact the way i think about
|  implicit parameters is simply as a nice notation for computations in
the
|  environment monad, so in my mind the above two definitions are
pretty
|  much the same.
| 
| Thanks Iavor!
| GHC people, can you confirm this, Is it a bug? I'm using Ghc 5.0.4
SuSE rpms.
| Is there a workaround?
| 
| Thanks,
| J.A.
| 
| 
| 
| ___
| Glasgow-haskell-users mailing list
| [EMAIL PROTECTED]
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: Bug? [was: Implicit params]

2002-11-18 Thread Jorge Adriano

 Now fixed in the HEAD, and will be in 5.04.2

 Thanks for pointing it out.

 Simon

Thanks :)
J.A.
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe