[Haskell-cafe] Haskell Weekly News: Issue 188

2011-06-29 Thread Daniel Santa Cruz
   Welcome to issue 188 of the HWN, a newsletter covering developments in
   the Haskell community. This release covers the week of June 19 to
   25, 2011.

   It was brought up in cafe this week that some would prefer to see
   full links in the text version of the mailing list as opposed to the
   shortened links. The reason behind using shortened links is that the
   newsletter becomes pretty much unreadable with long links in a plain
   text buffer. In an effort to accommodate both needs, I'm trying a new
   format for links. One that includes shorter links embedded throughout
   the newsletter, and the full reference at the bottom of the text. Let
   me know what you think!

   If you are reading this on a mobile device, or you would just rather
   see the HTML version, point your browser to:

   
http://contemplatecode.blogspot.com/2011/06/haskell-weekly-news-issue-188.html

Announcements

   Alex Mason wrote in to remind us that AusHac2011 (the Australasian
   Haskell Hackathon) will be held on July 8-10, at UNSW in Sydney. "If
   you are an Australian haskell hacker, enthusiast, newbie or
   professional, we would love to see you there."
   [2] http://goo.gl/d0SXy


   Florent Becker announced the release of darcs 2.8 beta 1, with many
   new beta features. Give it a world and let the devs know how things are
   working!
   [3] http://goo.gl/rq3DM

Quotes of the Week

   * <[~func...@zygohistomorphic-prepromorphism.endofunctor.org] has
 joined #haskell

   * kmc: actually, C++'s "typename" keyword is inspired by INTERCAL's
 "PLEASE"

   * Toxaris: #haskell delivers a massively multiprogrammer online
 functional programming (MMOFP) experience

   * sully: although I'm switching to haskell more and more just on
 practical grounds

   * mauke: the greek letter lambda is an imperfect approximation of the
 symbol \

   * Cale: The trouble with sarcasm is that in order for it to really be
 effective, the listener has to know what the speaker knows.
 Otherwise, it's indistinguishable from ignorance.

Top Reddit Stories

   * Haskell's evaluation isn't magic.
 Domain: netsuperbrain.com, Score: 42, Comments: 33
 On Reddit: [4] http://goo.gl/jD8jM
 Original: [5] http://goo.gl/31pyt

   * Superclass equalities are now supported
 Domain: hackage.haskell.org, Score: 40, Comments: 16
 On Reddit: [6] http://goo.gl/5PuUh
 Original: [7] http://goo.gl/XhrMR

   * Free Monads for Less (Part 1 of 3): Codensity
 Domain: comonad.com, Score: 35, Comments:
 On Reddit: [8] http://goo.gl/mqkDi
 Original: [9] http://goo.gl/9eWLr

   * Renewed LambdaCube 3D engine, Bullet bindings and Stunts example
 Domain: just-bottom.blogspot.com, Score: 33, Comments: 2
 On Reddit: [10] http://goo.gl/UsP59
 Original: [11] http://goo.gl/YR3sH

   * A new design for haskell.org
 Domain: chrisdone.com, Score: 31, Comments: 47
 On Reddit: [12] http://goo.gl/044JZ
 Original: [13] http://goo.gl/Hvivh

   * Free Monads for Less (Part 2 of 3): Yoneda
 Domain: comonad.com, Score: 25, Comments:
 On Reddit: [14] http://goo.gl/K6fI9
 Original: [15] http://goo.gl/bjV5f

   * Free Monads for Less (Part 3 of 3): Yielding IO
 Domain: comonad.com, Score: 24, Comments:
 On Reddit: [16] http://goo.gl/pKXUR
 Original: [17] http://goo.gl/EDxzo

   * Snap Framework v0.5.1 released
 Domain: snapframework.com, Score: 20, Comments: 2
 On Reddit: [18] http://goo.gl/sKsqq
 Original: [19] http://goo.gl/Chk6j

   * Comparing FRP to RDP (Reactive Demand Programming)
 Domain: awelonblue.wordpress.com, Score: 19, Comments: 2
 On Reddit: [20] http://goo.gl/0wEgx
 Original: [21] http://goo.gl/B4dYs

   * Haskell eDSL Tutorial - Shared expenses
 Domain: lpenz.org, Score: 18, Comments: 11
 On Reddit: [22] http://goo.gl/6yf5j
 Original: [23] http://goo.gl/t14Xs

Top StackOverflow Questions

   * How do you write data structures that are as efficient as possible in GHC?
 votes: 26, answers: 2
 Read on SO: [24] http://goo.gl/cj18P

   * How does seq force functions?
 votes: 15, answers: 1
 Read on SO: [25] http://goo.gl/f1TX8

   * I/O in Haskell is Functional?
 votes: 14, answers: 5
 Read on SO: [26] http://goo.gl/ZT0HQ

   * Exponentiation in Haskell
 votes: 12, answers: 4
 Read on SO: [27] http://goo.gl/ueo1A

   * How to compile a resource into a binary in Haskell?
 votes: 12, answers: 4
 Read on SO: [28] http://goo.gl/mxDPV

   * Haskell Heap Issues with Parameter Passing Style
 votes: 12, answers: 2
 Read on SO: [29] http://goo.gl/b2m10

   * Functor is for (a -> b) -> (f a -> f b), what is for (Category c)
=> c a b -> c (f a) (f b) ?
 votes: 12, answers: 1
 Read on SO: [30] http://goo.gl/Usv7I

   * Better way to write the following program in Haskell
 votes: 12, answers: 7
 Read on SO: [31] http://goo.gl/Dn7Xj

About the Haskell Weekly News

   To help create ne

Re: [Haskell-cafe] [Haskell-beginners] Understanding category theory

2011-06-29 Thread Jack Henahan
Derp, forgot to CC the Cafe.

  Which ones have you read already? It's difficult to make recommendations 
without knowing what's already off the table.

Additionally, don't be put off if it takes a lot of effort to figure anything 
out. Math textbooks and so on are unlike any other textbook. It's not unusual 
to spend a day (or several days) trying to digest a single page of material 
unless you have a strong mathematical background (or even if you do). This is 
especially true in the more abstract disciplines (and if there's anything more 
abstract than category theory, I don't think I've yet encountered it).


On Jun 29, 2011, at 8:26 PM, Christopher Howard wrote:

> Would anyone recommend a particular book or tutorial to help me understand 
> category theory? I've tried reading a few tutorials i've googled, but even 
> the "beginner" ones are very difficult and seem to assume a lot.
> 
> Sent from my HTC
> 
> ___
> Beginners mailing list
> beginn...@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners




"Computer Science is no more about computers than astronomy is about 
telescopes."
-- Edsger Dijkstra




398E692F.asc
Description: application/apple-msg-attachment




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] overloading show function

2011-06-29 Thread Philipp Schneider
Thank you very much, this worked.

On 06/30/2011 12:03 AM, aditya siram wrote:
> Try enabling OverlappingInstances extension by adding this to the top
> of the file:
> {-# LANGUAGE OverlappingInstances #-}
>
> -deech
>
> On Wed, Jun 29, 2011 at 4:50 PM, Philipp Schneider
>  wrote:
>> Hi cafe,
>>
>> in my program i use a monad of the following type
>>
>> newtype M a = M (State -> (a, State))
>>
>> i use the monad in two different ways. The type variable "a" can be a
>> pair as in
>>
>> interp :: Term -> Environment -> M (Value,Environment)
>>
>> and it can be just a value as in
>>
>> type Environment = [(Name, Either Value (M Value))]
>>
>> now in any case when i print the monad, i just want to print the value
>> and never the environment.
>>
>> More specific i want to use somthing like the following
>>
>> instance (Show a,Show b) => Show (M (a,b)) where
>>   show (M f) = let ((v,_), s) = f 0 in
>> "Value: " ++ show v ++  " Count: " ++ show s
>>
>> instance Show a => Show (M a) where
>>   show (M f) = let (v, s) = f 0 in
>> "Value: " ++ show v ++  " Count: " ++ show s
>>
>> however this gives me the following error message:
>>
>>Overlapping instances for Show (M (Value, Environment))
>>  arising from a use of `print'
>>Matching instances:
>>  instance (Show a, Show b) => Show (M (a, b))
>>-- Defined at
>> /home/phil/code/haskell/vorlesung/ue09/ue09-3c3.hs:78:10-42
>>  instance Show a => Show (M a)
>>-- Defined at
>> /home/phil/code/haskell/vorlesung/ue09/ue09-3c3.hs:82:10-29
>>In a stmt of an interactive GHCi command: print it
>>
>> Any ideas how to fix it? Thanks!
>> Philipp
>>
>> ___
>> 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] Exclusive mode in openFile

2011-06-29 Thread Felipe Almeida Lessa
On Wed, Jun 29, 2011 at 7:11 PM, Gracjan Polak  wrote:
> Proper way to handle this is probably to add additional Bool parameter to 
> mkFD,
> fdToHandle and GHC.IO.FD.openFile that says if Report's semantics should be 
> held
> or not. Then openFileShared can be build on top of that.
>
> (Possibly primed versions of these function will be needed to keep backward
> compatibility)
>
> If this could help anybody else out there beside me I could make this proposal
> more concrete and follow library change procedure properly. If not I can live
> with what I have hacked together till now.
>
> Is there any interest in such a change?

There should be at least something on the docs of openFile.  But I
think that openFileShared may be handy.

Cheers!

-- 
Felipe.

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


Re: [Haskell-cafe] Exclusive mode in openFile

2011-06-29 Thread Gracjan Polak
Gracjan Polak  gmail.com> writes:
> 
> I'm looking for file locking code in GHC.IO.* modules, but cannot find any.
> 

Just for the record: locking code resides in GHC.IO.FD in mkFD which calls
lockFile.

There is a heavy machinery underneath that is working hard to ensure Report's
semantics. Somebody must have spent a lot of effort in this place. Nice!


> How do I convince fdToHandle to create an independent handle to non-locked
> file?
 

Proper way to handle this is probably to add additional Bool parameter to mkFD,
fdToHandle and GHC.IO.FD.openFile that says if Report's semantics should be held
or not. Then openFileShared can be build on top of that.

(Possibly primed versions of these function will be needed to keep backward
compatibility)

If this could help anybody else out there beside me I could make this proposal
more concrete and follow library change procedure properly. If not I can live
with what I have hacked together till now.

Is there any interest in such a change?

-- 
Gracjan



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


Re: [Haskell-cafe] overloading show function

2011-06-29 Thread Steffen Schuldenzucker


Hi Philipp,

On 06/29/2011 11:50 PM, Philipp Schneider wrote:

Hi cafe,

in my program i use a monad of the following type

newtype M a = M (State ->  (a, State))


btw., it looks like you just rebuilt the State monad.



...

instance (Show a,Show b) =>  Show (M (a,b)) where
show (M f) = let ((v,_), s) = f 0 in
  "Value: " ++ show v ++  " Count: " ++ show s

instance Show a =>  Show (M a) where
show (M f) = let (v, s) = f 0 in
  "Value: " ++ show v ++  " Count: " ++ show s

however this gives me the following error message:

 Overlapping instances for Show (M (Value, Environment))
   arising from a use of `print'
 Matching instances:
   instance (Show a, Show b) =>  Show (M (a, b))
 -- Defined at
/home/phil/code/haskell/vorlesung/ue09/ue09-3c3.hs:78:10-42
   instance Show a =>  Show (M a)
 -- Defined at
/home/phil/code/haskell/vorlesung/ue09/ue09-3c3.hs:82:10-29
 In a stmt of an interactive GHCi command: print it


This is a well-known issue. The problem is as follows: Your second 
instance declares an instance Show (M a) for any type a. If a is of the 
Form (b, c), we can derive a tuple instance from that. This however 
conflicts with the tuple instance declared above.


If you want GHC to choose the most specific instance (which would be 
your first one for tuples), use the


{-# LANGUAGE OverlappingInstances #-}

pragma. Be careful with this however, as it might lead to unexpected 
results. For a similar problem, you may want to consult the haskell wiki[1].


-- Steffen

[1] http://haskell.org/haskellwiki/GHC/AdvancedOverlap

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


Re: [Haskell-cafe] overloading show function

2011-06-29 Thread aditya siram
Try enabling OverlappingInstances extension by adding this to the top
of the file:
{-# LANGUAGE OverlappingInstances #-}

-deech

On Wed, Jun 29, 2011 at 4:50 PM, Philipp Schneider
 wrote:
> Hi cafe,
>
> in my program i use a monad of the following type
>
> newtype M a = M (State -> (a, State))
>
> i use the monad in two different ways. The type variable "a" can be a
> pair as in
>
> interp :: Term -> Environment -> M (Value,Environment)
>
> and it can be just a value as in
>
> type Environment = [(Name, Either Value (M Value))]
>
> now in any case when i print the monad, i just want to print the value
> and never the environment.
>
> More specific i want to use somthing like the following
>
> instance (Show a,Show b) => Show (M (a,b)) where
>   show (M f) = let ((v,_), s) = f 0 in
>     "Value: " ++ show v ++  " Count: " ++ show s
>
> instance Show a => Show (M a) where
>   show (M f) = let (v, s) = f 0 in
>     "Value: " ++ show v ++  " Count: " ++ show s
>
> however this gives me the following error message:
>
>    Overlapping instances for Show (M (Value, Environment))
>      arising from a use of `print'
>    Matching instances:
>      instance (Show a, Show b) => Show (M (a, b))
>        -- Defined at
> /home/phil/code/haskell/vorlesung/ue09/ue09-3c3.hs:78:10-42
>      instance Show a => Show (M a)
>        -- Defined at
> /home/phil/code/haskell/vorlesung/ue09/ue09-3c3.hs:82:10-29
>    In a stmt of an interactive GHCi command: print it
>
> Any ideas how to fix it? Thanks!
> Philipp
>
> ___
> 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] overloading show function

2011-06-29 Thread Philipp Schneider
Hi cafe,

in my program i use a monad of the following type

newtype M a = M (State -> (a, State))

i use the monad in two different ways. The type variable "a" can be a
pair as in

interp :: Term -> Environment -> M (Value,Environment)

and it can be just a value as in

type Environment = [(Name, Either Value (M Value))]

now in any case when i print the monad, i just want to print the value
and never the environment.

More specific i want to use somthing like the following

instance (Show a,Show b) => Show (M (a,b)) where
   show (M f) = let ((v,_), s) = f 0 in
 "Value: " ++ show v ++  " Count: " ++ show s

instance Show a => Show (M a) where
   show (M f) = let (v, s) = f 0 in
 "Value: " ++ show v ++  " Count: " ++ show s

however this gives me the following error message:

Overlapping instances for Show (M (Value, Environment))
  arising from a use of `print'
Matching instances:
  instance (Show a, Show b) => Show (M (a, b))
-- Defined at
/home/phil/code/haskell/vorlesung/ue09/ue09-3c3.hs:78:10-42
  instance Show a => Show (M a)
-- Defined at
/home/phil/code/haskell/vorlesung/ue09/ue09-3c3.hs:82:10-29
In a stmt of an interactive GHCi command: print it

Any ideas how to fix it? Thanks!
Philipp

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


Re: [Haskell-cafe] How to flush with IterIO in echo server

2011-06-29 Thread dm-list-haskell-cafe
At Wed, 29 Jun 2011 21:13:47 +1000,
John Ky wrote:
> 
> Hi Haskell Cafe,
> 
> I've written an echo server using just sockets:
> 
> ...
> 
> When I send text to it, it will echo it back immediately after my newline.
> 
> I then modified it to user IterIO:
> 
> import Control.Concurrent
> import Control.Exception
> import Control.Monad
> import Control.Monad.Trans
> import Data.IterIO
> import Data.IterIO.Inum
> import Network
> import System.IO
> import System.IO.Error (isEOFError)
> import qualified Data.ByteString.Lazy as L
>
> iterHandle' :: (MonadIO m) => Handle -> IO (Iter L.ByteString m (), Onum
> L.ByteString m a)
> iterHandle' = iterHandle
>
> main = withSocketsDo $ do
>   sListen <- listenOn (PortNumber 8000)
>   putStrLn "Listening on Port 8000"
>   forkIO $ forever $ do
>     (sSession, hostname, port) <- accept sListen
>     putStrLn ("Connected to " ++ hostname ++ ":" ++ show port)
>     forkIO $ do
>       (iter, enum) <- iterHandle' sSession
>       enum |$ iter
>       return ()
>   putStrLn "Press  to quit."
>   exitOnCtrlD
>
> exitOnCtrlD = try getLine >>= either
>   (\e -> unless (isEOFError e) $ ioError e)
>   (const exitOnCtrlD)
> 
> It works, however it doesn't send anything back to me until end of file.
> 
> I fixed that problem with my sockets version by flushing after each line, but
> I don't know if IterIO will let me flush on every newline.

The buffering is actually happening in the Handle code.  One way to
avoid this is to change your code to call hSetBuffering as follows:

  hSetBuffering sSession NoBuffering
  (iter, enum) <- iterHandle' sSession

This is mentioned in the documentation of handleI, but arguably should
also be there in the docs for iterHandle.  I think I'll add a mention
there.

If you use Sockets and call iterStream, that should also avoid the
problem.

David

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


[Haskell-cafe] hmatrix-static with ghc 7.0.2

2011-06-29 Thread Anand Patil
Hi all,

Has anyone managed to get hmatrix-static to compile with ghc 7.0.2,
and if so would you be willing to share a patch?

With best wishes,
Anand

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


Re: [Haskell-cafe] attoparsec and vectors

2011-06-29 Thread Gregory Collins
On Wed, Jun 29, 2011 at 4:16 AM, Roman Leshchinskiy  
wrote:
> Gregory Collins wrote:
>> For an example of a similar technique (minus the freezing part), I did
>> a similar thing in the hashtables library:
>
> You might be interested in 'grow' :-)

I would be, except to save a couple of words I used a more primitive
array type than vector :)

G
-- 
Gregory Collins 

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


[Haskell-cafe] How to flush with IterIO in echo server

2011-06-29 Thread John Ky
Hi Haskell Cafe,

I've written an echo server using just sockets:

import Control.Concurrent
import Control.Exception
import Control.Monad
import Network
import Offsync.Data
import System.IO
import System.IO.Error (isEOFError)

main = withSocketsDo $ do
  sListen <- listenOn (PortNumber 8000)
  putStrLn "Listening on Port 8000"
  forkIO $ forever $ do
(sSession, hostname, port) <- accept sListen
putStrLn ("Connected to " ++ hostname ++ ":" ++ show port)
forkIO $ echoLines sSession
  putStrLn "Press  to quit."
  exitOnCtrlD

echoLines h = try (hGetLine h) >>= either
  (\e -> do { hClose h; if isEOFError e then print e else ioError e})
  (\l -> do { hPutStrLn h l; hFlush h; echoLines h})

exitOnCtrlD = try getLine >>= either
  (\e -> unless (isEOFError e) $ ioError e)
  (const exitOnCtrlD)


When I send text to it, it will echo it back immediately after my newline.

I then modified it to user IterIO:

import Control.Concurrent
import Control.Exception
import Control.Monad
import Control.Monad.Trans
import Data.IterIO
import Data.IterIO.Inum
import Network
import System.IO
import System.IO.Error (isEOFError)
import qualified Data.ByteString.Lazy as L

iterHandle' :: (MonadIO m) => Handle -> IO (Iter L.ByteString m (), Onum
L.ByteString m a)
iterHandle' = iterHandle

main = withSocketsDo $ do
  sListen <- listenOn (PortNumber 8000)
  putStrLn "Listening on Port 8000"
  forkIO $ forever $ do
(sSession, hostname, port) <- accept sListen
putStrLn ("Connected to " ++ hostname ++ ":" ++ show port)
forkIO $ do
  (iter, enum) <- iterHandle' sSession
  enum |$ iter
  return ()
  putStrLn "Press  to quit."
  exitOnCtrlD

exitOnCtrlD = try getLine >>= either
  (\e -> unless (isEOFError e) $ ioError e)
  (const exitOnCtrlD)


It works, however it doesn't send anything back to me until end of file.

I fixed that problem with my sockets version by flushing after each line,
but I don't know if IterIO will let me flush on every newline.

Any ideas?

Cheers,

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


Re: [Haskell-cafe] Exclusive mode in openFile

2011-06-29 Thread Gracjan Polak
Max Bolingbroke  hotmail.com> writes:
>
http://hackage.haskell.org/packages/archive/unix/2.4.2.0/doc/html/System-Posix-IO.html.

Thanks for the link. I tried to use it:

Prelude System.Posix.IO> fd1 <- openFd "xxx.tmp" WriteOnly (Just 0666)
defaultFileFlags
Loading package unix-2.4.0.2 ... linking ... done.
Prelude System.Posix.IO> fd2 <- openFd "xxx.tmp" WriteOnly (Just 0666)
defaultFileFlags
Prelude System.Posix.IO> print (fd1,fd2)
(5,7)
Prelude System.Posix.IO> h1 <- fdToHandle fd1
Prelude System.Posix.IO> h2 <- fdToHandle fd2
*** Exception: openFile: resource busy (file is locked)

So I can open file twice. So far so good. Then I convert Fds to Handles and
second conversion fails.

I'm looking for file locking code in GHC.IO.* modules, but cannot find any.

How do I convince fdToHandle to create an independent handle to non-locked file?

-- 
Gracjan



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


Re: [Haskell-cafe] Possible bug in GHC 7.0.3

2011-06-29 Thread Daniel Fischer
On Wednesday 29 June 2011, 11:37:39, Yitzchak Gale wrote:
> 
> So it's the derived Read instance in this context that
> is causing the problem. Here is a slightly smaller test
> case that triggers the bug:
> 
> {-# LANGUAGE MultiParamTypeClasses, UndecidableInstances #-}
> module Bug where
> class A a oops
> data D d = D d
> instance A a oops => Read (D a)
> data E e = E (D e) deriving Read

Just for the record, same panic with 7.0.2 and 7.0.4 (and deriving Show or 
Eq too).
6.12.3 reports:

Can't derive instances where the instance context mentions
type variables that are not data type parameters
  Offending constraint: A e oops
When deriving the instance for (Read (E e))

which seems reasonable.


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


Re: [Haskell-cafe] Possible bug in GHC 7.0.3

2011-06-29 Thread Yitzchak Gale
Daniel Fischer wrote:
> No, the instance head is just a type variable, not a type constructor
> applied to type variables

Oops, you're right. GHC was telling the truth, I should have
paid closer attention!

Fixing my minimal example, I get:

{-# LANGUAGE MultiParamTypeClasses, UndecidableInstances #-}
module ClassContextBug where
class A a oops
class B b
data D d = D d
instance A a oops => B (D a)

and now GHC compiles it happily.

So it's the derived Read instance in this context that
is causing the problem. Here is a slightly smaller test
case that triggers the bug:

{-# LANGUAGE MultiParamTypeClasses, UndecidableInstances #-}
module Bug where
class A a oops
data D d = D d
instance A a oops => Read (D a)
data E e = E (D e) deriving Read

Thanks,
Yitz

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


Re: [Haskell-cafe] Possible bug in GHC 7.0.3

2011-06-29 Thread Daniel Fischer
On Wednesday 29 June 2011, 10:22:20, Yitzchak Gale wrote:
> Ryan Ingram wrote:
> > So this is definitely a GHC bug, but I think the problem is probably
> > triggered by this line:
> > 
> > instance  Serializable a b => IResource a
> > 
> > I don't think this is a valid instance declaration without a
> > functional dependency on Serializable, as it's impossible to know
> > which type 'b' to use in the methods of IResource.
> 
> That's not exactly the reason why that line is a problem.
> The methods of IResource don't use b. Presumably, some of
> the methods of Serializable don't mention b either, and those
> could be used in the instance.
> 
> But what exactly does this instance mean? Where does the
> implicit "forall b" go? For this to make any sense, it would
> need to be:
> 
> -- Illegal syntax for instance
> instance (forall b. Serializable a b => IResource a)
> 
> I don't think it has ever been specified whether it is legal
> to have free type variables as parameters of a multi-parameter
> class in the superclass context of an instance declaration,
> and if so, how to interpret that.
> 
> Haskell 98/2010 does seem to allow it for single-parameter
> classes, but there the obvious meaning would be just to
> ignore those parts of the context.
> 
> In any case, GHC does seem to be getting very confused.
> Here is a smaller test case. While it does not trigger the
> crash, it does cause GHC to give a seemingly nonsensical
> error message:
> 
> module ClassContextBug where
> class A a
> class B b
> instance A a => B b
> 
> ClassContextBug.hs:5:17:
> Illegal instance declaration for `B b'
>   (All instance types must be of the form (T a1 ... an)
>where a1 ... an are *distinct type variables*,
>and each type variable appears at most once in the instance head.
>Use -XFlexibleInstances if you want to disable this.)
> In the instance declaration for `B b'
> 
> I believe this is valid Haskell 98, so GHC should accept it.

No, the instance head is just a type variable, not a type constructor 
applied to type variables, so it's not allowed by H98 (nor H2010, I think, 
haven't looked it up, but since GHC defaults to 2010 now, I'm pretty sure).
So GHC rightly complains about the malformed instance head. If you enable 
FlexibleInstances, it gives

ClassContextBug.hs:5:10:
Ambiguous constraint `A a'
  At least one of the forall'd type variables mentioned by the 
constraint
  must be reachable from the type after the '=>'
In the instance declaration for `B b'

ClassContextBug.hs:5:10:
Variable occurs more often in a constraint than in the instance head
  in the constraint: A a
(Use -XUndecidableInstances to permit this)
In the instance declaration for `B b'

which is exactly what is wrong with the instance declaration.

> But even if not, what GHC is claiming in the error message
> is simply not true.
> 
> I would like to add this to the bug report.
> Alberto, have you filed the bug report yet? Can you please post a link?
> 
> Thanks,
> Yitz


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


Re: [Haskell-cafe] Possible bug in GHC 7.0.3

2011-06-29 Thread Alberto G. Corona
http://hackage.haskell.org/trac/ghc/ticket/5287
El 29/06/2011 10:22, "Yitzchak Gale"  escribió:
> Ryan Ingram wrote:
>> So this is definitely a GHC bug, but I think the problem is probably
>> triggered by this line:
>>
>> instance  Serializable a b => IResource a
>>
>> I don't think this is a valid instance declaration without a functional
>> dependency on Serializable, as it's impossible to know which type 'b' to
use
>> in the methods of IResource.
>
> That's not exactly the reason why that line is a problem.
> The methods of IResource don't use b. Presumably, some of
> the methods of Serializable don't mention b either, and those
> could be used in the instance.
>
> But what exactly does this instance mean? Where does the
> implicit "forall b" go? For this to make any sense, it would
> need to be:
>
> -- Illegal syntax for instance
> instance (forall b. Serializable a b => IResource a)
>
> I don't think it has ever been specified whether it is legal
> to have free type variables as parameters of a multi-parameter
> class in the superclass context of an instance declaration,
> and if so, how to interpret that.
>
> Haskell 98/2010 does seem to allow it for single-parameter
> classes, but there the obvious meaning would be just to
> ignore those parts of the context.
>
> In any case, GHC does seem to be getting very confused.
> Here is a smaller test case. While it does not trigger the
> crash, it does cause GHC to give a seemingly nonsensical
> error message:
>
> module ClassContextBug where
> class A a
> class B b
> instance A a => B b
>
> ClassContextBug.hs:5:17:
> Illegal instance declaration for `B b'
> (All instance types must be of the form (T a1 ... an)
> where a1 ... an are *distinct type variables*,
> and each type variable appears at most once in the instance head.
> Use -XFlexibleInstances if you want to disable this.)
> In the instance declaration for `B b'
>
> I believe this is valid Haskell 98, so GHC should accept it.
> But even if not, what GHC is claiming in the error message
> is simply not true.
>
> I would like to add this to the bug report.
> Alberto, have you filed the bug report yet? Can you please post a link?
>
> Thanks,
> Yitz
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Possible bug in GHC 7.0.3

2011-06-29 Thread Yitzchak Gale
Ryan Ingram wrote:
> So this is definitely a GHC bug, but I think the problem is probably
> triggered by this line:
>
> instance  Serializable a b => IResource a
>
> I don't think this is a valid instance declaration without a functional
> dependency on Serializable, as it's impossible to know which type 'b' to use
> in the methods of IResource.

That's not exactly the reason why that line is a problem.
The methods of IResource don't use b. Presumably, some of
the methods of Serializable don't mention b either, and those
could be used in the instance.

But what exactly does this instance mean? Where does the
implicit "forall b" go? For this to make any sense, it would
need to be:

-- Illegal syntax for instance
instance (forall b. Serializable a b => IResource a)

I don't think it has ever been specified whether it is legal
to have free type variables as parameters of a multi-parameter
class in the superclass context of an instance declaration,
and if so, how to interpret that.

Haskell 98/2010 does seem to allow it for single-parameter
classes, but there the obvious meaning would be just to
ignore those parts of the context.

In any case, GHC does seem to be getting very confused.
Here is a smaller test case. While it does not trigger the
crash, it does cause GHC to give a seemingly nonsensical
error message:

module ClassContextBug where
class A a
class B b
instance A a => B b

ClassContextBug.hs:5:17:
Illegal instance declaration for `B b'
  (All instance types must be of the form (T a1 ... an)
   where a1 ... an are *distinct type variables*,
   and each type variable appears at most once in the instance head.
   Use -XFlexibleInstances if you want to disable this.)
In the instance declaration for `B b'

I believe this is valid Haskell 98, so GHC should accept it.
But even if not, what GHC is claiming in the error message
is simply not true.

I would like to add this to the bug report.
Alberto, have you filed the bug report yet? Can you please post a link?

Thanks,
Yitz

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


Re: [Haskell-cafe] attoparsec and vectors

2011-06-29 Thread Roman Leshchinskiy
Gregory Collins wrote:
> On Tue, Jun 28, 2011 at 6:20 PM, Eric Rasmussen 
> wrote:
>
>> It runs quickly, but I naively thought I could outperform it by
>> reworking "many" to build a vector directly, instead of having to build
>> a list first and then convert it to a vector:
>>
>> manyVec :: Alternative f => f a -> f (V.Vector a) manyVec v = many_v  
>> where many_v = some_v <|> pure V.empty         some_v = V.cons
>> <$> v <*> many_v
>>
>
> That's an O(n^2) loop, and a thunk leak to boot. If you don't know the
> size of the vector ahead of time, the only way I can think of to beat
> Vector.fromList is to use a mutable vector with a "highwater" mark,
> and double the size if you fill it. At the end, you'd use "unsafeFreeze" to
> turn the mutable vector into a pure one, and "unsafeTake" to truncate the
> vector into the correct size.

That's basically what fromList does. You could do this at a higher
abstraction level by generating a Stream rather than a list and then using
unstream to create a vector. I don't know if it's possible to do that with
attoparsec. But you'd only save allocating and deallocating a lazily
consumed list anyway. I'm not sure if it will be even noticable compared
to how much parsing costs.

> For an example of a similar technique (minus the freezing part), I did
> a similar thing in the hashtables library:

You might be interested in 'grow' :-)

http://hackage.haskell.org/packages/archive/vector/0.7.1/doc/html/Data-Vector-Generic-Mutable.html#g:8

Roman




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


Re: [Haskell-cafe] Possible bug in GHC 7.0.3

2011-06-29 Thread Alberto G. Corona
Ryan'
P robably the read instance can not be infered without the functional
dependency but the bug is also triggered with it. I simplified ithe coder as
much as possible
El 29/06/2011 02:26, "Ryan Ingram"  escribió:
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] IterIO type restricted functions

2011-06-29 Thread John Ky
Hi David,

Good point.  Not too fussed, though now that I think about it, I would have
preferred it if enumFile' was defined in the tutorial rather than in the
module.

Cheers,

-John

On 29 June 2011 13:53,  wrote:

> At Wed, 29 Jun 2011 10:11:26 +1000,
> John Ky wrote:
> >
> > [1  ]
> > [1.1  ]
> >
> > Hi all,
> >
> > From the IterIO tutorial:
> >
> > enumFile' is like enumFile above, but type restricted to data in the
> lazy
> > ByteString format, which is more efficient than plain Strings.
> (enumFile
> > supports multiple types, but in this example there is not enough
> > information for Haskell to choose one of them, so we must use
> enumfile' or
> > use :: to specify a type explicitly.
> >
> > Which is fine, but shouldn't there also be iterHandle' and iterStream'?
> >
> > Also I'm guessing the f is a typo that should be F.
>
> Thanks, just fixed the typo in git.
>
> I guess the logic is that these are super-easy to define in your own
> code, so better not to pollute the namespace with lots of symbols.
>
> The same logic also applies to enumFile'.  However, in testing I found
> that I often wanted something like enumFile' to prototype something
> quick and dirty, just to test from a file.  So I added it as a
> convenience to myself.
>
> I don't have very strong feelings either way.  If enumFile' is
> inconsistent, my inclination would be to get rid of enumFile' rather
> than add iterHandle' etc.  That way, if someone wants to do everything
> in terms of strict byte strings, or text, or whatever, then can just
> define the primed versions to be whatever data format they prefer.
>
> I guess the reason it doesn't feel to horrible as-is is that enumFile
> is already a convenience function effectively combining openFile with
> enumHandle.
>
> David
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe