[Haskell-cafe] understanding enumerator/iteratee

2008-12-20 Thread Jason Dusek
  So, it looks Iteratee takes a "step" on the resource --
  whatever it is -- and Enumerator manages the resource and
  sequences the steps of the Iteratee. The Enumerator, then,
  defines our way of managing a particular resource -- how to
  take a step, how to close it, &c. -- while the Iteratee
  describes a computation that computes an output and also tells
  us when to free the resource.

  Is that a correct interpretation? I find the material on
  Enumerator and Iterator to be vague (or at least not very
  concrete).

  I have seen code for a random access Iteratee/Enumerator pair,
  as well. In that case, the role of the Iteratee is to provide
  the "next step" to take -- one of forward , backward ,
  close?

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


Re: [Haskell-cafe] Re: [reactive] problem with unamb -- doesn't kill enough threads

2008-12-20 Thread Peter Verswyvelen
I see. Of course, how silly of me, killThread is asynchronous, it only waits
until the exception is raised in the receiving thread, but it does not wait
until the thread is really killed. The documentation does not seem to
mention this explicitly.

Now, what would be the clean way to make sure all threads are indeed killed
before the process quits? I tried to add another MVar that gets set after
the thread handles uncatched exceptions (so something like bracket (forkIO
a) (putMVar quit ()) return) and the code that calls killThread then does
takeMVar quit, but this did not solve the  problem.

A yield didn't do it for me on Windows, I had a to put in a  rather large
threadDelay of 1/10th of a second...

On Sat, Dec 20, 2008 at 6:25 AM, Conal Elliott  wrote:

> Oh -- I think the problem here was simply that the process itself exited
> before all of the threads had a chance to get killed.  When I add a short
> sleep to the end of main, or even just a 'yield', I see that all threads
> reported as killed.  What clued me in was finally paying attention to the
> observation that under ghci I get the new prompt *before* some of the kill
> reports.
>
>   - Conal
>
>
> On Fri, Dec 19, 2008 at 11:17 AM, Conal Elliott  wrote:
>
>> Peter,
>>
>> Thanks for digging.  In your results below, I see only three out of four
>> threads killed even in the best case.  Each time, there is no report of the
>> 'sleep 2' thread being killed.
>>
>> When I run your code on Linux (Ubuntu 8.10), everything looks great when
>> run under ghci.  If compiled, with and without -threaded and with and
>> without +RTS -N2, I sometimes get four kill messages and sometimes fewer.
>> In the latter case, I don't know if the other threads aren't getting killed
>> or if they're killed but not reported.
>>
>> For example (removing messages other than "Killed"):
>>
>> co...@compy-doble:~/Haskell/Misc$ rm Threads.o ; ghc Threads.hs
>> -threaded -o Threads && ./Threads +RTS -N2
>> Killed ThreadId 5
>> Killed ThreadId 4
>>
>> co...@compy-doble:~/Haskell/Misc$ ./Threads +RTS -N2
>> Killed ThreadId 5
>> Killed ThreadId 4
>> Killed ThreadId 7
>> Killed ThreadId 6
>>
>> co...@compy-doble:~/Haskell/Misc$ ./Threads +RTS -N2
>> Killed ThreadId 5
>> Killed ThreadId 7
>> Killed ThreadId 4
>> Killed ThreadId 6
>>
>> co...@compy-doble:~/Haskell/Misc$ ./Threads +RTS -N2
>> Killed ThreadId 5
>> Killed ThreadId 4
>>
>> co...@compy-doble:~/Haskell/Misc$
>>
>> Simon -- does this behavior look like a GHC bug to you?
>>
>>- Conal
>>
>>
>> On Fri, Dec 19, 2008 at 9:45 AM, Peter Verswyvelen wrote:
>>
>>> I played a bit the the bracket function that timeout uses, but got
>>> strange results (both on Windows and OSX).
>>>
>>> Ugly code fragment follows:
>>>
>>>
>>> -%<-
>>>
>>> import Prelude hiding (catch)
>>>
>>> import Control.Concurrent
>>> import Control.Concurrent.MVar
>>> import Control.Exception
>>> import System.IO
>>> import Data.Char
>>>
>>> withThread a b = bracket (forkIO a) kill (const b)
>>> where
>>>   kill id = do
>>> putStrLn ("Killing "++show id++"\n")
>>> killThread id
>>> putStrLn ("Killed "++show id++"\n")
>>>
>>> race a b = do
>>> v <- newEmptyMVar
>>> let t x = x >>= putMVar v
>>> withThread (t a) $ withThread (t b) $ takeMVar v
>>>
>>> forkPut :: IO a -> MVar a -> IO ThreadId
>>> forkPut act v = forkIO ((act >>= putMVar v) `catch` uhandler `catch`
>>> bhandler)
>>>  where
>>>uhandler (ErrorCall "Prelude.undefined") = return ()
>>>uhandler err = throw err
>>>bhandler BlockedOnDeadMVar   = return ()
>>>
>>> sleep n = do
>>>   tid <- myThreadId
>>>   putStrLn ("Sleeping "++show n++" sec on "++show tid++"\n")
>>>   threadDelay (n*100)
>>>   putStrLn ("Slept "++show n++" sec on "++show tid++"\n")
>>>
>>> f = sleep 2 `race` sleep 3
>>>
>>> g = f `race` sleep 1
>>>
>>> main = do
>>>   hSetBuffering stdout LineBuffering
>>>   g
>>>
>>>
>>> -%<-
>>>
>>> Here's the output when running with GHCI:
>>>
>>> C:\temp>runghc racetest
>>> Sleeping 1 sec on ThreadId 26
>>> Sleeping 2 sec on ThreadId 27
>>> Sleeping 3 sec on ThreadId 28
>>> Slept 1 sec on ThreadId 26
>>> Killing ThreadId 26
>>> Killed ThreadId 26
>>> Killing ThreadId 25
>>> Killed ThreadId 25
>>> Killing ThreadId 28
>>> Killed ThreadId 28
>>>
>>> Fine, all threads got killed.
>>>
>>> Here's the output from an EXE compiled with GHC -threaded, but run
>>> without +RTS -N2
>>>
>>> C:\temp> racetest
>>> Sleeping 1 sec on ThreadId 5
>>> Sleeping 3 sec on ThreadId 7
>>> Sleeping 2 sec on ThreadId 6
>>> Slept 1 sec on ThreadId 5
>>> Killing ThreadId 5
>>> Killed ThreadId 5
>>> Killing ThreadId 4
>>> Killed ThreadId 4
>>> Killing ThreadId 7
>>>
>>> So "Kil

Re: [Haskell-cafe] Re: [reactive] problem with unamb -- doesn't kill enough threads

2008-12-20 Thread Thomas Davie


On 20 Dec 2008, at 12:00, Peter Verswyvelen wrote:

I see. Of course, how silly of me, killThread is asynchronous, it  
only waits until the exception is raised in the receiving thread,  
but it does not wait until the thread is really killed. The  
documentation does not seem to mention this explicitly.


Now, what would be the clean way to make sure all threads are indeed  
killed before the process quits? I tried to add another MVar that  
gets set after the thread handles uncatched exceptions (so something  
like bracket (forkIO a) (putMVar quit ()) return) and the code that  
calls killThread then does takeMVar quit, but this did not solve  
the  problem.


I'm not sure I understand what the "problem" is – if the process has  
died, why do we want to kill threads?


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


[Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Martijn van Steenbergen

Hi Neil,

This is awesome, thank you. :-) It found a 'use liftM', 'use on' and 
three eta-reduces in Yogurt.


It seems like the line numbers could be a bit more accurate:

./Network/Yogurt/IO.hs:54:3: Use liftM
Found:
  rec >>= return . (c :)
Why not:
  liftM (c :) rec

Where the code is:

50 -- Waits for input, but once the first character is read, waits
51 -- no longer than the specified number of ms before giving up.
52 hGetImpatientLine :: Handle -> Int -> IO String
53 hGetImpatientLine h patience = rec where
54   rec = do
55 c <- hGetChar h
56 if c == '\n'
57   then return [c]
58   else do
59 b <- hWaitForInput h patience
60 if b
61   then rec >>= return . (c:)
62   else return [c]

I imagine it could have told me to look at line 61 right away.

Thanks,

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


[Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Hugo Pacheco
Hi again,

I have run HLint against my libraries and found lots of suggestions, mainly
excessive brackets.

This is what I suggest from my experience:
. a suggestion for a rule: dollar eta: f $ x -> f x. some parser errors I
encountered: import Data.Generics hiding ((:*:))
type instance Rep Id x =
x

Cheers,
hugo

On Sat, Dec 20, 2008 at 10:21 AM, Hugo Pacheco  wrote:

> I noticed that you convert point-wise into point-free.Perhaps you could
> add some point-free transformations to remove redundancy in certain cases.
> Is that a goal of the library?
>
> Cheers,
> hugo
>
>
> On Sat, Dec 20, 2008 at 9:55 AM, Neil Mitchell wrote:
>
>> Hi,
>>
>> I am pleased to announce HLint, a tool for making suggestions to
>> improve your Haskell code. Previously this tool was called Dr Haskell
>> and depended on a working installation of Yhc - both of those have now
>> changed. HLint requires GHC 6.10*, and to install simply type:
>>
>> cabal update && cabal install hlint
>>
>> If you haven't yet installed the cabal command, instructions are here:
>> http://ghcmutterings.wordpress.com/2008/11/10/bootstrapping-cabal-install/
>>
>> As an example of what HLint does, running "hlint darcs-2.1.2" over the
>> latest stable release of darcs gives 385 suggestions, including:
>>
>> darcs-2.1.2\src\CommandLine.lhs:46:1: Use a string literal
>> Found:
>>  [' ', '\t', '"', '%']
>> Why not:
>>  " \t\"%"
>>
>> darcs-2.1.2\src\CommandLine.lhs:49:1: Eta reduce
>> Found:
>>  quotedArg ftable
>>= between (char '"') (char '"') $ quoteContent ftable
>> Why not:
>>  quotedArg = between (char '"') (char '"') . quoteContent
>>
>> darcs-2.1.2\src\CommandLine.lhs:94:1: Use concatMap
>> Found:
>>  concat $ map escapeC s
>> Why not:
>>  concatMap escapeC s
>>
>> To see all the hints in a nice interactive document visit
>> http://www-users.cs.york.ac.uk/~ndm/hlint/hlint-report.htm
>> (recommended if you are thinking of trying out hlint)
>>
>> All necessary links, including a manual, hackage links, bug tracker
>> and source code can be found from the tool website:
>> http://www-users.cs.york.ac.uk/~ndm/hlint/
>>
>> Acknowledgements: Niklas Broberg and the haskell-src-exts package have
>> both been very helpful. The darcs users mailing list gave many good
>> suggestions which I've incorportated.
>>
>> Please direct any follow up conversations to haskell-cafe@
>>
>> Thanks
>>
>> Neil
>>
>> * Why GHC 6.10? View patterns.
>> ___
>> Haskell mailing list
>> hask...@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell
>>
>
>
>
> --
> www.di.uminho.pt/~hpacheco
>



-- 
www.di.uminho.pt/~hpacheco
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Niklas Broberg
> It seems like the line numbers could be a bit more accurate:
>
> ./Network/Yogurt/IO.hs:54:3: Use liftM
> Found:
>  rec >>= return . (c :)
> Why not:
>  liftM (c :) rec
>
> Where the code is:
>
> 50 -- Waits for input, but once the first character is read, waits
> 51 -- no longer than the specified number of ms before giving up.
> 52 hGetImpatientLine :: Handle -> Int -> IO String
> 53 hGetImpatientLine h patience = rec where
> 54   rec = do
> 55 c <- hGetChar h
> 56 if c == '\n'
> 57   then return [c]
> 58   else do
> 59 b <- hWaitForInput h patience
> 60 if b
> 61   then rec >>= return . (c:)
> 62   else return [c]
>
> I imagine it could have told me to look at line 61 right away.

You can blame HSE in this case, it only stores line numbers for
certain constructs, and expressions are not among them. The closest
predictable construct for this case is the RHS of the function
definition, which is why you get line 54. This is something I hope to
improve in HSE over time.

Cheers,

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


Re: [Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Niklas Broberg
> . some parser errors I encountered: import Data.Generics hiding ((:*:))
> type instance Rep Id x = x

The first is due to a bug in HSE which I've now fixed, thanks a lot
for reporting! The second is parsed just fine by HSE so I don't know
what's up there.

Cheers,

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


Re: [Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Martijn van Steenbergen

Hi Neil,

Another question:

Darcs/Commands/Optimize.lhs:110:1: Use isPrefixOf, and then remove the 
(==) test

Found:
take 4 (just_name pinfo) == "TAG "
Why not:
(4 == length "TAG ") && ("TAG " `isPrefixOf` just_name pinfo)

I assume the (==) referred to in the name of the fix is the one in the 
suggestion. Why doesn't the suggestion come with the check removed? I.e.:


Why not:
("TAG " `isPrefixOf` just_name pinfo)

Thanks,

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


[Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Gwern Branwen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

On Sat, Dec 20, 2008 at 4:55 AM, Neil Mitchell  wrote:
> Hi,
>
> I am pleased to announce HLint, a tool for making suggestions to
> improve your Haskell code. Previously this tool was called Dr Haskell
> and depended on a working installation of Yhc - both of those have now
> changed. HLint requires GHC 6.10*, and to install simply type:
>
> cabal update && cabal install hlint
>
> If you haven't yet installed the cabal command, instructions are here:
> http://ghcmutterings.wordpress.com/2008/11/10/bootstrapping-cabal-install/
>
> As an example of what HLint does, running "hlint darcs-2.1.2" over the
> latest stable release of darcs gives 385 suggestions, including:
>
> darcs-2.1.2\src\CommandLine.lhs:46:1: Use a string literal
> Found:
>  [' ', '\t', '"', '%']
> Why not:
>  " \t\"%"
>
> darcs-2.1.2\src\CommandLine.lhs:49:1: Eta reduce
> Found:
>  quotedArg ftable
>= between (char '"') (char '"') $ quoteContent ftable
> Why not:
>  quotedArg = between (char '"') (char '"') . quoteContent
>
> darcs-2.1.2\src\CommandLine.lhs:94:1: Use concatMap
> Found:
>  concat $ map escapeC s
> Why not:
>  concatMap escapeC s
>
> To see all the hints in a nice interactive document visit
> http://www-users.cs.york.ac.uk/~ndm/hlint/hlint-report.htm
> (recommended if you are thinking of trying out hlint)
>
> All necessary links, including a manual, hackage links, bug tracker
> and source code can be found from the tool website:
> http://www-users.cs.york.ac.uk/~ndm/hlint/
>
> Acknowledgements: Niklas Broberg and the haskell-src-exts package have
> both been very helpful. The darcs users mailing list gave many good
> suggestions which I've incorportated.
>
> Please direct any follow up conversations to haskell-cafe@
>
> Thanks
>
> Neil
>
> * Why GHC 6.10? View patterns.

Hi, Neil. Thanks for the tool; it found some worthwhile changes in my projects.

But a few points:
1) How does one actually use the CLI tool? You didn't say. It *seems*
that one just feeds it a list of random filepaths, so on Mueval, say,
the command would be 'hlint main.hs Mueval/*.hs' (and not, say, 'hlint
mueval.cabal'). But I'm not actually sure.
2) I think I found a parsing bug. One line in Mueval/Interpreter.hs runs:

> fmap (take n exceptionMsg ++) $ render' (n-length exceptionMsg) s

which gives the error:

> Mueval/Interpreter.hs:145:59: Parse failure, Parse error
> No relevant suggestions

Adding spaces between 'n' and 'length', so it reads:

> fmap (take n exceptionMsg ++) $ render' (n - length exceptionMsg) s

lets hlint parse and suggest for it.

- --
gwern
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEAREKAAYFAklM+kwACgkQvpDo5Pfl1oKDhwCfRgQutbvr9QbKvbLJlbhdla2Z
absAniWC+ksXHhfbunsdOsnmG69lppFZ
=X9uv
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Bulat Ziganshin
Hello Martijn,

Saturday, December 20, 2008, 4:38:10 PM, you wrote:

> Why not:
> (4 == length "TAG ") && ("TAG " `isPrefixOf` just_name pinfo)

> I assume the (==) referred to in the name of the fix is the one in the
> suggestion. Why doesn't the suggestion come with the check removed? I.e.:

due to Turing computability problem, i believe :)  although Neil may
try to run it in separate thread :)


-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

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


Re: Re[2]: [Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Felipe Lessa
On Sat, Dec 20, 2008 at 12:28 PM, Bulat Ziganshin
 wrote:
> Saturday, December 20, 2008, 4:38:10 PM, you wrote:
>> Why not:
>> (4 == length "TAG ") && ("TAG " `isPrefixOf` just_name pinfo)
>
>> I assume the (==) referred to in the name of the fix is the one in the
>> suggestion. Why doesn't the suggestion come with the check removed? I.e.:
>
> due to Turing computability problem, i believe :)  although Neil may
> try to run it in separate thread :)

In the general case it is, but most of the time we use a constant as
first argument to isPrefixOf and as such its length may be calculated
in finite (and very small) time. This is a special case worth taking
care of, I think.

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


[Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Neil Mitchell
Hi

> I noticed that you convert point-wise into point-free.
> Perhaps you could add some point-free transformations to remove redundancy
> in certain cases.
> Is that a goal of the library?

It does some transformations of th at nature, but the idea isn't to
remove redundancy, its to make the code clearer. Do you have any
suggestions for things it could easily do to remove redundancy? It
already does a few relating to if expressions.

> a suggestion for a rule: dollar eta: f $ x -> f x

That can easily be added.

> Why not:
> ("TAG " `isPrefixOf` just_name pinfo)

That's an open bug: http://code.google.com/p/ndmitchell/issues/detail?id=109

In general, most of the hints are "replace this with this" -
evaluating the new bit (even to remove easy constants) is beyond it
for the moment. Some people theorised it might be too hard,
non-terminating, or incorrect. As it happens this rule only fires when
"TAG " is either a string literal or a list literal, and when the
number is a constant, so its always safe and the guard could always be
eliminated.

> 1) How does one actually use the CLI tool? You didn't say. It *seems*
> that one just feeds it a list of random filepaths, so on Mueval, say,
> the command would be 'hlint main.hs Mueval/*.hs' (and not, say, 'hlint
> mueval.cabal'). But I'm not actually sure.

The filenames are either filenames, or directories which are
recursively searched, i.e cd mueval && hlint . is probably sufficient.
I should document it more clearly in the manual.

Thanks

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


[Haskell-cafe] I hate constructing strings with ++

2008-12-20 Thread Thomas Hartman
I hate constructing strings with ++. Especially icky when you start
dealing with escape characters and stuff.

cabal install HStringTemplateHelpers

.

import Text.StringTemplate.Helpers
putStrLn $ render1 [("name",name)] "Why, hello, $name$"

just thinkin out loud :)

(originally at 
http://www.reddit.com/r/programming/comments/7khkd/the_fun_of_programming_a_collection_of_haskell/p6iP)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: I hate constructing strings with ++

2008-12-20 Thread Thomas Hartman
Correction:

> name = "Bill"
> import Text.StringTemplate.Helpers
> putStrLn $ render1 [("name",name)] "Why, hello, $name$"


2008/12/20 Thomas Hartman :
> I hate constructing strings with ++. Especially icky when you start
> dealing with escape character and stuff.
>
> cabal install HStringTemplateHelpers
>
> .
>
> import Text.StringTemplate.Helpers
> putStrLn $ render1 [("name",name)] "Why, hello, $name$"
>
> just thinkin out loud :)
>
> (originally at 
> http://www.reddit.com/r/programming/comments/7khkd/the_fun_of_programming_a_collection_of_haskell/p6iP)
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Hugo Pacheco
On Sat, Dec 20, 2008 at 3:06 PM, Neil Mitchell  wrote:

> Hi
>
> > I noticed that you convert point-wise into point-free.
> > Perhaps you could add some point-free transformations to remove
> redundancy
> > in certain cases.
> > Is that a goal of the library?
>
> It does some transformations of th at nature, but the idea isn't to
> remove redundancy, its to make the code clearer. Do you have any
> suggestions for things it could easily do to remove redundancy?


There are many simple ones, such as:
f . id -> f
filter true -> id
map id -> id
... etc


> It
> already does a few relating to if expressions.
>

Yes, like map f . map g -> map (f . g)

You can find more in Transformation of Structure-Shy Programs - Applied to
XPath Queries and Strategic
Functions,
page
4.

>
> > a suggestion for a rule: dollar eta: f $ x -> f x
>
> That can easily be added.
>
> > Why not:
> > ("TAG " `isPrefixOf` just_name pinfo)
>
> That's an open bug:
> http://code.google.com/p/ndmitchell/issues/detail?id=109
>
> In general, most of the hints are "replace this with this" -
> evaluating the new bit (even to remove easy constants) is beyond it
> for the moment. Some people theorised it might be too hard,
> non-terminating, or incorrect. As it happens this rule only fires when
> "TAG " is either a string literal or a list literal, and when the
> number is a constant, so its always safe and the guard could always be
> eliminated.
>
> > 1) How does one actually use the CLI tool? You didn't say. It *seems*
> > that one just feeds it a list of random filepaths, so on Mueval, say,
> > the command would be 'hlint main.hs Mueval/*.hs' (and not, say, 'hlint
> > mueval.cabal'). But I'm not actually sure.
>
> The filenames are either filenames, or directories which are
> recursively searched, i.e cd mueval && hlint . is probably sufficient.
> I should document it more clearly in the manual.
>
> Thanks
>
> Neil
>



-- 
www.di.uminho.pt/~hpacheco
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] "non-functions like unsafePerformIO are not technically part of the haskell language!"

2008-12-20 Thread Jason Dusek
  From an old thread:

> non-functions like unsafePerformIO are not technically part
> of the haskell language!

  How is this true, exactly?

--
_jsn


 |...an old thread.|
  http://www.nabble.com/Re%3A-Re%3A-Parsers-are-monadic--p11390440.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] "non-functions like unsafePerformIO are not technically part of the haskell language!"

2008-12-20 Thread Lennart Augustsson
The current official Haskell standard is Haskell-98.  There is no
unsafePerformIO in there.

On Sat, Dec 20, 2008 at 3:33 PM, Jason Dusek  wrote:
>  From an old thread:
>
>> non-functions like unsafePerformIO are not technically part
>> of the haskell language!
>
>  How is this true, exactly?
>
> --
> _jsn
>
>
>  |...an old thread.|
>  http://www.nabble.com/Re%3A-Re%3A-Parsers-are-monadic--p11390440.html
> ___
> 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] "non-functions like unsafePerformIO are not technically part of the haskell language!"

2008-12-20 Thread Luke Palmer
On Sat, Dec 20, 2008 at 8:33 AM, Jason Dusek  wrote:

>  From an old thread:
>
> > non-functions like unsafePerformIO are not technically part
> > of the haskell language!
>
>  How is this true, exactly?


The Haskell 98 report (http://www.haskell.org/onlinereport/), according to
my cursory scan, makes no mention of unsafePerformIO.

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


Re: [Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Niklas Broberg
Hi Gwern,

> 2) I think I found a parsing bug. One line in Mueval/Interpreter.hs runs:
>
>> fmap (take n exceptionMsg ++) $ render' (n-length exceptionMsg) s
>
> which gives the error:
>
>> Mueval/Interpreter.hs:145:59: Parse failure, Parse error
>> No relevant suggestions
>
> Adding spaces between 'n' and 'length', so it reads:
>
>> fmap (take n exceptionMsg ++) $ render' (n - length exceptionMsg) s
>
> lets hlint parse and suggest for it.

This is clearly a HSE bug, and seeing your example I know exactly the
oversight I've made. Unfortunately I don't see immediately how to fix
it so I'll have to think on it for a while. Thanks for reporting it!

Cheers,

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


[Haskell-cafe] Beginner's TH question

2008-12-20 Thread Jeff Heard
Two things...  can I add fields to records using Template Haskell, like:

data T = T { $fields, myfield :: Field, ... }

I assume the answer there is no, and then what's wrong with this?  I get:

Illegal instance declaration for `UIState t'
(All instance types must be of the form (T a1 ... an)
 where a1 ... an are 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 `UIState t'
In the expression:
[d|
instance UIState t where
{ setSizeY v a = setSizeY v . uist $ a
  setSizeX v a = setSizeX v . uist $ a
  setDrawing v a = setDrawing v . uist $ a
  setKey v a = setKey v . uist $ a
   } |]
In the definition of `deriveUIState':
deriveUIState uist t
= [d|
  instance UIState t where
  { setSizeY v a = setSizeY v . uist $ a
setSizeX v a = setSizeX v . uist $ a
setDrawing v a = setDrawing v . uist $ a
 } |]

in this module:

-# LANGUAGE TemplateHaskell #-}
module Graphics.Rendering.Thingie.TH where

import Language.Haskell.TH
import Graphics.Rendering.Thingie.UIState
import qualified Graphics.Rendering.Thingie.BasicUIState as S


deriveUIState uist t =
  [d| instance UIState t where
mousePosition a = S.mousePosition . uist $ a
mouseLeftButtonDown a = S.mouseLeftButtonDown . uist $ a
mouseRightButtonDown a = S.mouseRightButtonDown . uist $ a
mouseMiddleButtonDown a = S.mouseMiddleButtonDown . uist $ a
mouseLeftButtonClicked a = S.mouseLeftButtonClicked . uist $ a
mouseRightButtonClicked a = S.mouseRightButtonClicked . uist $ a
mouseMiddleButtonClicked a = S.mouseMiddleButtonClicked . uist $ a
mouseWheel a = S.mouseWheel . uist $ a
keyCtrl a = S.keyCtrl . uist $ a
keyShift a = S.keyShift . uist $ a
keyAlt a = S.keyAlt . uist $ a
key a = S.key . uist $ a
drawing a = S.drawing . uist $ a
sizeX a = S.sizeX . uist $ a
sizeY a = S.sizeY . uist $ a
setMousePosition v a = setMousePosition v . uist $ a
setMouseLeftButtonDown v a = setMouseLeftButtonDown v . uist $ a
setMouseRightButtonDown v a = setMouseRightButtonDown v . uist $ a
setMouseMiddleButtonDown v a = setMouseMiddleButtonDown v . uist $ a
setMouseLeftButtonClicked v a = setMouseLeftButtonClicked
v . uist $ a
setMouseRightButtonClicked v a =
setMouseRightButtonClicked v . uist $ a
setMouseMiddleButtonClicked v a =
setMouseMiddleButtonClicked v . uist $ a
setMouseWheel v a = setMouseWheel v . uist $ a
setKeyCtrl v a = setKeyCtrl v . uist $ a
setKeyShift v a = setKeyShift v . uist $ a
setKeyAlt v a = setKeyAlt v . uist $ a
setKey v a = setKey v . uist $ a
setDrawing v a = setDrawing v . uist $ a
setSizeX v a = setSizeX v . uist $ a
setSizeY v a = setSizeY v . uist $ a
   |]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Logos of Other Languages

2008-12-20 Thread Niklas Broberg
> All of these get one thing right that the current and most of the proposed
> Haskell logos do not: they don't make any reference to the syntax of the
> language itself. Doing so seems to miss the point of a logo: it's supposed
> to appeal visually, rather than semantically. So I'd like to see some
> submissions that don't use lambdas.

Interesting how perceptions can vary. Of all the logos you linked to,
only the Python logo is anywhere near visually appealing to me, and
even that seems a bit much. Less is more (which incidentally is a
concept that also relates very well to Haskell's powerful abstraction
mechanisms), and that is doubly so in a logo. I want a logo that could
be adapted to be used in a lot of different situations, from t-shirts
to favicons to mascots, sometimes even with slightly different
connotations and references. I want a logo that I could draw fairly
accurately on a piece of paper in 10 seconds. And as such, I vastly
prefer many of those suggested on the wiki to all those you've
presented here. I think all of those shown here get all the things
I've mentioned wrong.

And the fact that others do it this way isn't really an argument
either. Since when has Haskell ever does something just because
everyone else does it that way? :-)

Cheers,

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


Re: [Haskell-cafe] Re: Logos of Other Languages

2008-12-20 Thread Niklas Broberg
> An homage to syntax at least gives an easily recognizable icon, far more
> iconic than a camel or a grid of colours, and I would consider several
> of the lambda based ideas on the wiki simple, elegant and visually
> appealing.

Exactly!

Cheers,

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


Re: [Haskell-cafe] "non-functions like unsafePerformIO are not technically part of the haskell language!"

2008-12-20 Thread Duncan Coutts
On Sat, 2008-12-20 at 15:43 +, Lennart Augustsson wrote:
> The current official Haskell standard is Haskell-98.  There is no
> unsafePerformIO in there.

It's in the FFI spec which is an official addendum to Haskell 98.
;-)

Duncan

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


Re: [Haskell-cafe] "non-functions like unsafePerformIO are not technically part of the haskell language!"

2008-12-20 Thread Lennart Augustsson
Bah!  I had nothing to do with that. ;)

On Sat, Dec 20, 2008 at 4:22 PM, Duncan Coutts
 wrote:
> On Sat, 2008-12-20 at 15:43 +, Lennart Augustsson wrote:
>> The current official Haskell standard is Haskell-98.  There is no
>> unsafePerformIO in there.
>
> It's in the FFI spec which is an official addendum to Haskell 98.
> ;-)
>
> Duncan
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Beginner's TH question

2008-12-20 Thread Bulat Ziganshin
Hello Jeff,

Saturday, December 20, 2008, 6:59:42 PM, you wrote:

my experience tells that you should insert whole language sentences,
like

$(add_fields [d| data T = T { myfield :: Field, ... } ] )

where original declaration passed as a parameter


> Two things...  can I add fields to records using Template Haskell, like:

> data T = T { $fields, myfield :: Field, ... }

> I assume the answer there is no, and then what's wrong with this?  I get:

> Illegal instance declaration for `UIState t'
> (All instance types must be of the form (T a1 ... an)
>  where a1 ... an are 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 `UIState t'
> In the expression:
> [d|
> instance UIState t where
> { setSizeY v a = setSizeY v . uist $ a
>   setSizeX v a = setSizeX v . uist $ a
>   setDrawing v a = setDrawing v . uist $ a
>   setKey v a = setKey v . uist $ a
>    } |]
> In the definition of `deriveUIState':
> deriveUIState uist t
> = [d|
>   instance UIState t where
>   { setSizeY v a = setSizeY v . uist $ a
> setSizeX v a = setSizeX v . uist $ a
> setDrawing v a = setDrawing v . uist $ a
>  } |]

> in this module:

> -# LANGUAGE TemplateHaskell #-}
> module Graphics.Rendering.Thingie.TH where

> import Language.Haskell.TH
> import Graphics.Rendering.Thingie.UIState
> import qualified Graphics.Rendering.Thingie.BasicUIState as S


> deriveUIState uist t =
>   [d| instance UIState t where
> mousePosition a = S.mousePosition . uist $ a
> mouseLeftButtonDown a = S.mouseLeftButtonDown . uist $ a
> mouseRightButtonDown a = S.mouseRightButtonDown . uist $ a
> mouseMiddleButtonDown a = S.mouseMiddleButtonDown . uist $ a
> mouseLeftButtonClicked a = S.mouseLeftButtonClicked . uist $ a
> mouseRightButtonClicked a = S.mouseRightButtonClicked . uist $ a
> mouseMiddleButtonClicked a = S.mouseMiddleButtonClicked . uist $ a
> mouseWheel a = S.mouseWheel . uist $ a
> keyCtrl a = S.keyCtrl . uist $ a
> keyShift a = S.keyShift . uist $ a
> keyAlt a = S.keyAlt . uist $ a
> key a = S.key . uist $ a
> drawing a = S.drawing . uist $ a
> sizeX a = S.sizeX . uist $ a
> sizeY a = S.sizeY . uist $ a
> setMousePosition v a = setMousePosition v . uist $ a
> setMouseLeftButtonDown v a = setMouseLeftButtonDown v . uist $ a
> setMouseRightButtonDown v a = setMouseRightButtonDown v . uist $ a
> setMouseMiddleButtonDown v a = setMouseMiddleButtonDown v . uist 
> $ a
> setMouseLeftButtonClicked v a = setMouseLeftButtonClicked
> v . uist $ a
> setMouseRightButtonClicked v a =
> setMouseRightButtonClicked v . uist $ a
> setMouseMiddleButtonClicked v a =
> setMouseMiddleButtonClicked v . uist $ a
> setMouseWheel v a = setMouseWheel v . uist $ a
> setKeyCtrl v a = setKeyCtrl v . uist $ a
> setKeyShift v a = setKeyShift v . uist $ a
> setKeyAlt v a = setKeyAlt v . uist $ a
> setKey v a = setKey v . uist $ a
> setDrawing v a = setDrawing v . uist $ a
> setSizeX v a = setSizeX v . uist $ a
> setSizeY v a = setSizeY v . uist $ a
>|]
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

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


Re: [Haskell-cafe] I hate constructing strings with ++

2008-12-20 Thread Johan Tibell
On Sat, Dec 20, 2008 at 4:15 PM, Thomas Hartman  wrote:
> I hate constructing strings with ++. Especially icky when you start
> dealing with escape characters and stuff.
>
> cabal install HStringTemplateHelpers
>
> .
>
> import Text.StringTemplate.Helpers
> putStrLn $ render1 [("name",name)] "Why, hello, $name$"

I once wrote a simple library for "classical" $-substitution. I plan
to upgrade it to use Data.Text (efficient bytestring like
representation for Unicode strings) whenever that's release.

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/template

Cheers,

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


Re: [Haskell-cafe] Beginner's TH question

2008-12-20 Thread Miguel Mitrofanov
Seems like GHC had already told you what's wrong. Instance  
declarations like "instance UIState t" are illegal without  
FlexibleInstances language feature enabled. Also, I don't quite  
understand, what you're trying to achieve; argument "t" and the letter  
"t" in the TH body are two different beasts, so your "derive..." would  
be of no use.


May be, you want something like this:

{-# LANGUAGE TemplateHaskell #-}
module TH where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
class C a where c :: a -> a
deriveC t =
 do decs <- [d| c x = x |]
   tp <- t
   return [InstanceD [] (AppT (ConT ''C) tp) decs]

{-# LANGUAGE TemplateHaskell #-}
module THTest where
import TH
$(deriveC [t| Int |])

*THTest> c (1 :: Int)
1

On 20 Dec 2008, at 18:59, Jeff Heard wrote:

Two things...  can I add fields to records using Template Haskell,  
like:


data T = T { $fields, myfield :: Field, ... }

I assume the answer there is no, and then what's wrong with this?  I  
get:


   Illegal instance declaration for `UIState t'
   (All instance types must be of the form (T a1 ... an)
where a1 ... an are 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 `UIState t'
   In the expression:
   [d|
   instance UIState t where
   { setSizeY v a = setSizeY v . uist $ a
 setSizeX v a = setSizeX v . uist $ a
 setDrawing v a = setDrawing v . uist $ a
 setKey v a = setKey v . uist $ a
  } |]
   In the definition of `deriveUIState':
   deriveUIState uist t
   = [d|
 instance UIState t where
 { setSizeY v a = setSizeY v . uist  
$ a
   setSizeX v a = setSizeX v . uist  
$ a
   setDrawing v a = setDrawing v .  
uist $ a

    } |]

in this module:

-# LANGUAGE TemplateHaskell #-}
module Graphics.Rendering.Thingie.TH where

import Language.Haskell.TH
import Graphics.Rendering.Thingie.UIState
import qualified Graphics.Rendering.Thingie.BasicUIState as S


deriveUIState uist t =
 [d| instance UIState t where
   mousePosition a = S.mousePosition . uist $ a
   mouseLeftButtonDown a = S.mouseLeftButtonDown . uist $ a
   mouseRightButtonDown a = S.mouseRightButtonDown . uist $ a
   mouseMiddleButtonDown a = S.mouseMiddleButtonDown . uist  
$ a
   mouseLeftButtonClicked a = S.mouseLeftButtonClicked .  
uist $ a
   mouseRightButtonClicked a = S.mouseRightButtonClicked .  
uist $ a
   mouseMiddleButtonClicked a = S.mouseMiddleButtonClicked .  
uist $ a

   mouseWheel a = S.mouseWheel . uist $ a
   keyCtrl a = S.keyCtrl . uist $ a
   keyShift a = S.keyShift . uist $ a
   keyAlt a = S.keyAlt . uist $ a
   key a = S.key . uist $ a
   drawing a = S.drawing . uist $ a
   sizeX a = S.sizeX . uist $ a
   sizeY a = S.sizeY . uist $ a
   setMousePosition v a = setMousePosition v . uist $ a
   setMouseLeftButtonDown v a = setMouseLeftButtonDown v .  
uist $ a
   setMouseRightButtonDown v a = setMouseRightButtonDown v .  
uist $ a
   setMouseMiddleButtonDown v a = setMouseMiddleButtonDown  
v . uist $ a

   setMouseLeftButtonClicked v a = setMouseLeftButtonClicked
v . uist $ a
   setMouseRightButtonClicked v a =
setMouseRightButtonClicked v . uist $ a
   setMouseMiddleButtonClicked v a =
setMouseMiddleButtonClicked v . uist $ a
   setMouseWheel v a = setMouseWheel v . uist $ a
   setKeyCtrl v a = setKeyCtrl v . uist $ a
   setKeyShift v a = setKeyShift v . uist $ a
   setKeyAlt v a = setKeyAlt v . uist $ a
   setKey v a = setKey v . uist $ a
   setDrawing v a = setDrawing v . uist $ a
   setSizeX v a = setSizeX v . uist $ a
   setSizeY v a = setSizeY v . uist $ a
  |]
___
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: Detecting system endianness

2008-12-20 Thread Maurí­cio

But why would you want that? I understand the only
situation when talking about number of bytes
makes sense is when you are using Foreign and
Ptr. (...)



Because I'm using both Ptr and Foreign? ;)

See my recent announcement for bytestring-trie. One of the optimizations 
I'm working on is to read off a full natural word at a time, (...)


I see, you mean the size of a machine word, not of Data.Word.

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


[Haskell-cafe] Re: [Haskell] ANN: HLint 1.0

2008-12-20 Thread Gwern Branwen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

So has anyone figured out how to integrate hlint with ghci? I've tried
several approaches.

Using hlint as a preprocessor (
http://www.haskell.org/ghc/docs/latest/html/users_guide/options-phases.html#pre-processor
) doesn't work because the pre-processor needs to take 3 args. Even if
one writes a wrapper shell script along the lines of 'cp $2 $3 &&
hlint $2', this still won't work. It apparently breaks when you load a
file which requires another file. I am not sure why.

I then thought to redefine :load and :reload in ghci; this would work
very well with Emacs and Yi, since they tell ghci to :load and :reload
buffers. Turns out, you're not allowed to overwrite :load and :reload.
You can do :def reload whatever to your heart's content, but the new
version never takes. (Not even if defined in .ghci.)

Alright. A :hlint would probably be enough. I can always edit Yi/Emacs
to follow a :reload/:load with a :hlint, after all. And aren't there
shell command primitives already?

So I set out, and I realize: I can't simply settle for some version of
:! "hlint .", because the working directory rarely changes - if one
opens ghci in ~/, and loads a file elsewhere, :pwd reveals one to
still be in ~/. And a 'hlint .' could take a very long time indeed in
~/.

Well, alright. I just need the file name of the module I'm working
with. Surely there is an easy way to do that. And indeed, :show
modules gives me what I'm looking for:

*Recorder Control.Monad Data.Char Data.List> :show modules
Util ( Util.hs, interpreted )
Recorder ( Recorder.hs, interpreted )
Game ( Game.hs, interpreted )
Monadius ( Monadius.hs, interpreted )
Demo ( Demo.hs, interpreted )

Well, sort of. Ok, we can parse that. Let's assume a variable x holds
the output of :show modules as a String. We call lines on it, then map
words on it, do a !! 2 on it, and we get ["Util.hs,", "Recorder.hs,",
"Game.hs,", "Monadius.hs,", "Demo.hs,"]. Chuck in a map (filter (\=
',')), and we get a good list. We can turn the list into a string
suitable for hlint with a quick unwords.

So our long sought after command becomes ':def hoogle (\_ -> return $
":! " ++ (unwords $ map (filter (\= ',')) $ (map words $ lines x) !!
2))'. But wait, how do we get 'x'? How do we call :show modules inside
a Haskell expression? I have carefully looked over
http://haskell.org/haskellwiki/GHC/GHCi#Using_GHCi and
http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-commands.html
and my conclusion is that you can't. You can't do a let x = :show
modules, there is no function which will take ":show modules", and so
on. :functions can accept Haskell output, but it's a one-way barrier.
It's no good writing Haskell functions which need information from the
:functions.

Which all leaves me where I started - no ghci integration with hlint. Any ideas?

- --
gwern
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEAREKAAYFAklNNSIACgkQvpDo5Pfl1oJwWgCfZJ7nwkHfsZymIRass0ewmhFE
en4AnjmQam3V8Go6pGoLTRsp5zZEzAms
=nmJm
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Trouble with FFI on Windows2000...

2008-12-20 Thread Serge LE HUITOUZE

Hi there!

I'm trying to FFI-bind a MS Visual dll (under Windows2000) to a Haskell program.


I have this little C(++) dll:
*** FILE inc.h: START ***
extern "C" {
  int pten(int i);
}
*** FILE inc.h: END   ***

*** FILE inc.cpp: START ***
#include "inc.h"
int pten(int i) {
  return i+10;
}
*** FILE inc.cpp: END   ***

*** FILE cproj1.def: START ***
LIBRARY cproj1
EXPORTS
pten
*** FILE cproj1.def: END   ***

And this little Haskell program:
*** FILE testFFI_2.hs: START ***
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Foreign.C -- get the C types
foreign import ccall unsafe "pten" c_pten :: CInt -> CInt
plus10 :: Int -> Int
plus10 i = fromIntegral (c_pten (fromIntegral i))
main = print (map plus10 [1..10])
*** FILE testFFI_2.lhs: END   ***

Using information found at paragraph 1.4.3.4 of 
http://www.haskell.org/haskellwiki/GHC:FAQ#GHC_on_Windows
I do the following:
> dlltool -d cproj1.def -l libcproj1.a
> ghc --make testFFI_2.hs -optl-lcproj1 -optl-L.

This seems fine, since it produces a "testFFI_2.exe".
However, executing it, I get a MSWindows error box with a message
that looks like (approximate translation): 
"DLL (null) not found on specified path"

At first, I didn't have the "LIBRARY" directive in the ".def" file,
so I thought that was the reason for the "(null)" appearing in the
message. But adding said directive didn't change anything...

[I've checked that my MSVisual dll was in current dir, and that this
dir was in the search paths showed in the error box]

Can anyone enlighten me?

Thanks in advance.

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


[Haskell-cafe] Pattern combinators

2008-12-20 Thread Andrew Wagner
All,
Wadler posted a blog entry the other day about a paper on pattern-matching
in Haskell (http://wadler.blogspot.com/). I've taken a first stab at turning
it into actual code for hackage (http://hpaste.org/13215). There are two
commented-out definitions that don't type-check, though, and the types are
too wild for me to grok. Anybody have any suggestions for 1.) How to fix it
and/or 2.) How to use data/type/newtype to simplify the types and make it
more manageable? Thanks!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Is this related to monomorphism restriction?

2008-12-20 Thread Maurí­cio

Hi,

Why isn't the last line of this code allowed?

f :: (TestClass a) => a -> Integer
f = const 1
a = (f,f)
g = fst a

The only thing I can think about is monomorphism
restriction, but it's allowed (or even the third
line would not be accepted). Is there something
I could read to understand that?

Thanks,
Maurício

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


Re: [Haskell-cafe] Is this related to monomorphism restriction?

2008-12-20 Thread Luke Palmer
On Sat, Dec 20, 2008 at 4:28 PM, Maurí­cio  wrote:

> Hi,
>
> Why isn't the last line of this code allowed?
>
> f :: (TestClass a) => a -> Integer
> f = const 1
> a = (f,f)
> g = fst a


Yep, monomorphism restriction.  a, because it is syntactically not a
function, must not be typeclass polymorphic (without a type signature).  So
it tries to default, and TestClass probably doesn't have any defaults.

Luke


>
>
> The only thing I can think about is monomorphism
> restriction, but it's allowed (or even the third
> line would not be accepted). Is there something
> I could read to understand that?
>
> Thanks,
> Maurício
>
> ___
> 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] Is this related to monomorphism restriction?

2008-12-20 Thread Reiner Pope
On Sun, Dec 21, 2008 at 10:28 AM, Maurí­cio  wrote:
> Hi,
>
> Why isn't the last line of this code allowed?
>
> f :: (TestClass a) => a -> Integer
> f = const 1
> a = (f,f)
> g = fst a
>
> The only thing I can think about is monomorphism
> restriction, but it's allowed (or even the third
> line would not be accepted). Is there something
> I could read to understand that?
>
> Thanks,
> Maurício
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

The monomorphism restriction refuses to accept the definition of a.
However, even if we turn the monomorphism restriction off there is
still a problem.

> {-# LANGUAGE NoMonomorphismRestriction #-}
>
> f :: (TestClass a) => a -> Integer
> f = const 1
> a = (f,f)
> g = fst a

In this case, the definition of a is accepted, but not the definition
of g. The reason is that a has type

a :: (TestClass a, TestClass b) => (a,b)

and then when we take 'fst' of this value (as in g) we get

g :: (TestClass a, TestClass b) => a

which is an ambiguous type, since there is no way to tell the compiler
what 'b' is when running g.

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


[Haskell-cafe] Type classes vr.s functions

2008-12-20 Thread Brian Hurt


So, style question for people, if I can.  I have a certain problem-
basically, I have a bunch of functions which need a special function,
of type a -> Foo say.  And a bunch of other functions which can define
that function on some type of interest, and then what to call the first
batch of functions.  I can do this either by defining a type class,
something like:
class Fooable a where
toFoo :: a -> Foo
or I can simply have all the functions which need a toFoo take an extra
agrument.  Performance really isn't that important here, so it's really
a matter of style- which approach would people prefer in this case?

Brian

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


Re: [Haskell-cafe] Haskell as a religion

2008-12-20 Thread Brian Hurt


(Sorry for the late reply)

On Tue, 16 Dec 2008, Andrew Coppin wrote:


Don Stewart wrote:

I think of Haskell more as a revolutionary movement


LOL! Longest revolution EVER, eh? I mean, how long ago was its dogma first 
codified? ;-)


Remember: the eternal union of soviet socialist states lasted about 7 
times as long as Hitler's thousand-year Reich (meanwhile, Jefferson's 
temporary experiment still seems to be lurching along about as well as 
ever).  Nothing is as permanent as that which is declared temporary, and 
nothing is as temporary as that which is declared permanent.  Also, 
constants aren't and variables don't.




The thing that saddens me is this:

http://prog21.dadgum.com/31.html

Basically, Haskell will never be popular, but its coolest ideas will be 
stolen by everybody else and passed off as their own. :-(


We should be so lucky.  My deepest fears is that Haskell doesn't become 
popular *and* it's ideas aren't picked up by other languages.


Brian

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


Re: [Haskell-cafe] Pattern combinators

2008-12-20 Thread Jacques Carette

Andrew Wagner wrote:
Wadler posted a blog entry the other day about a paper on 
pattern-matching in Haskell (http://wadler.blogspot.com/). I've taken 
a first stab at turning it into actual code for hackage 
(http://hpaste.org/13215). There are two commented-out definitions 
that don't type-check, though, and the types are too wild for me to 
grok. Anybody have any suggestions for 1.) How to fix it and/or 2.) 
How to use data/type/newtype to simplify the types and make it more 
manageable? Thanks!
Both errors are because you are using "any" instead of "any'"; you might 
wish to put

import Prelude hiding any
at the top of your code, just to avoid such confusion.

To make the types more readable (but not necessarily more manageable), I 
have made some changes to my version of this code.  For example, instead 
of () as the "empty stack", I use

data Void
void = undefined :: Void
in the definition of 'zero' (and thus also in p .>. k).  I also use
data FUnit = FUnit  -- Unit just for fail
Lastly, instead of having a matcher be a pair (which obscures the use of 
pairs as a stack in other places, as well as matching on pairs), I defined

data Matcher a b = Matcher a b
and use that everywhere.

This all makes the types larger to type, but at least there is a cleaner 
separation of concerns, which makes the errors easier to figure out.


The principal weakness of these pattern-matching combinators is that 
there is no support for algebraic types, i.e. things like

data Tree a = Leaf | Branch (Tree a) (Tree a)
I can see how to use Typeable to deal with that, but is there a simpler way?

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


[Haskell-cafe] Cabal Install & Links to Source from Haddock Docs

2008-12-20 Thread R Hayes


Is there a way I can get Haddock Docs WITH links to source (local)  
from modules installed with "cabal install xxx"?


Getting the docs themselves is pretty easy by changing either ~/.cabal/ 
config or using --enable-documentation.


Automatically generating the source (colourised or not) and integrated  
links eludes me.


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


Re: [Haskell-cafe] understanding enumerator/iteratee

2008-12-20 Thread Artyom Shalkhakov
Hi Jason,

2008/12/20 Jason Dusek :
>  So, it looks Iteratee takes a "step" on the resource --
>  whatever it is -- and Enumerator manages the resource and
>  sequences the steps of the Iteratee. The Enumerator, then,
>  defines our way of managing a particular resource -- how to
>  take a step, how to close it, &c. -- while the Iteratee
>  describes a computation that computes an output and also tells
>  us when to free the resource.

Yes, I believe you are correct.

>  Is that a correct interpretation? I find the material on
>  Enumerator and Iterator to be vague (or at least not very
>  concrete).

Have you read Oleg's DEFUN'08 talk notes? [1] Having
read them more than once, I find them comprehensible. :)

Cheers,
Artyom Shalkhakov.

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


Re: [Haskell-cafe] Type classes vr.s functions

2008-12-20 Thread Brandon S. Allbery KF8NH

On 2008 Dec 20, at 20:20, Brian Hurt wrote:

class Fooable a where
   toFoo :: a -> Foo
or I can simply have all the functions which need a toFoo take an  
extra
agrument.  Performance really isn't that important here, so it's  
really

a matter of style- which approach would people prefer in this case?



A third possibility is to use the simple Reader monad ((->) r).

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH


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


Re: [Haskell-cafe] Haskell as a religion

2008-12-20 Thread Brandon S. Allbery KF8NH

On 2008 Dec 20, at 20:35, Brian Hurt wrote:
We should be so lucky.  My deepest fears is that Haskell doesn't  
become popular *and* it's ideas aren't picked up by other languages.



No worries:  they *are* being picked up, piece by piece.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH


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


Re: [Haskell-cafe] Pattern combinators

2008-12-20 Thread David Menendez
On Sat, Dec 20, 2008 at 9:34 PM, Jacques Carette  wrote:
> Andrew Wagner wrote:
>>
>> Wadler posted a blog entry the other day about a paper on pattern-matching
>> in Haskell (http://wadler.blogspot.com/). I've taken a first stab at turning
>> it into actual code for hackage (http://hpaste.org/13215). There are two
>> commented-out definitions that don't type-check, though, and the types are
>> too wild for me to grok. Anybody have any suggestions for 1.) How to fix it
>> and/or 2.) How to use data/type/newtype to simplify the types and make it
>> more manageable? Thanks!
>
> Both errors are because you are using "any" instead of "any'"; you might
> wish to put
> import Prelude hiding any
> at the top of your code, just to avoid such confusion.

Example 14 also uses (.->.) where it should use (.>.), and it either
needs some more parentheses or some precedence declarations for the
operators.

> To make the types more readable (but not necessarily more manageable), I
> have made some changes to my version of this code.

One oddity in the paper is the type of the failure continuations, ()
-> ans. I'm guessing that's left over from an earlier phase of
development. In my own transcription of the library, I eliminated the
() parameter without apparent loss of functionality.

I think I've managed to work out the structure of the types, which can
mostly be expressed in modern Haskell.

The matching part of the patterns have this general form:

type PMatch vec vec' ans = (vec -> ans) -> (() -> ans) -> vec' -> ans

where vec and vec' are the list of argument types before and after the
subpattern match, and ans is the final answer. (In my code, I just use
ans instead of () -> ans for the failure continuation.)

This gets us:

nil   :: PMatch vec vec ans
one   :: a -> PMatch (a,vec) vec ans
(#)   :: PMatch vec vec' ans -> PMatch vec' vec'' ans -> PMatch vec vec'' ans
fail  :: PMatch vec vec' ans
catch :: PMatch vec vec' ans -> PMatch vec vec' ans -> PMatch vec vec' ans

These types are less general than the ones Haskell would infer, but
they do not appear to lose any functionality.

The currying part of the pattern is less easy to analyze. I've been
able to use type families to relate the curried and uncurried form of
the function types, but I'm working with GHC 6.8, so it's possible
this won't work with the more modern implementations.

Given the list of argument types and the answer type, generate a
curried function type:

type family Curry vec ans
type instance Curry () ans = ans
type instance Curry (a,vec) ans = a -> Curry vec ans

zero, succ zero, and so forth take a function in curried form and
transform it into a function that takes a nested tuple:

type CurryDigit vec ans = Curry vec ans -> vec -> ans

zero :: CurryDigit () ans
succ zero :: CurryDigit (a,()) ans

succ :: CurryDigit vec ans -> CurryDigit (a,vec) ans
succ . succ :: CurryDigit vec ans -> CurryDigit (a,(b,vec)) ans

So the currying part of the pattern will have the form:

type PCurry vec vec' ans = CurryDigit vec' ans -> CurryDigit vec ans

So a pattern has the type,

type Pattern a vec vec' ans = (PCurry vec vec' ans, a -> PMatch
vec vec' ans)

where a is the value being examined, vec and vec' are the list of
unbound argument types before and after the match, and ans is the
result.

var :: Pattern a (a,vec) vec ans
cst :: (Eq a) => a -> Pattern a vec vec ans
pair :: Pattern a vec vec' ans -> Pattern b vec' vec'' ans ->
Pattern (a,b) vec vec'' ans


Coming from the other side, match takes a value and a case statement
and produces a result:

type Case a ans = a -> (() -> ans) -> ans   -- or just a -> ans ->
ans in my code

match :: a -> Case a ans -> ans

(|||) combines case statements:

(|||) :: Case a ans -> Case a ans -> Case a ans

and (->>) creates them from a pattern and a curried function,

(->>) :: Pattern a vec () ans -> Curry vec ans -> Case a ans

Note that (->>) requires the pattern to leave no unbound variables
after matching.


Given the way everything is polymorphic in ans, it may be possible to
hide it, but I haven't tried yet.


> The principal weakness of these pattern-matching combinators is that there
> is no support for algebraic types, i.e. things like
> data Tree a = Leaf | Branch (Tree a) (Tree a)
> I can see how to use Typeable to deal with that, but is there a simpler way?

You can define the patterns manually:

leaf = (id, \v -> case v of { Leaf -> nil; _ -> fail })

branch p q = (curry_p . curry_q, \v -> case v of { Branch l r ->
match_p l # match_q r; _ -> fail})
where
(curry_p, match_p) = p
(curry_q, match_q) = q

I assume generating these would be pretty straightforward to automate
with Template Haskell.

-- 
Dave Menendez 

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


[Haskell-cafe] Graham Hutton's calculator example for win32

2008-12-20 Thread Ahn, Ki Yung
In Graham Hutton's "Programming in Haskell" there is an interactive
calculator example using ANSI code to implement the UI on the terminal.
This example doesn't work on MS Windows XP or other MS OSes based on NT
kernel, since their command line does not support ANSI very well.

But, thanks to ansi-terminal on Hackage, I was able to extract minimal
code from the package to make a win32 version of the calculator example
in Hutton's book.

calculatorWin32.lhs and Win32ANSI.hs is an implementation for win32.
I extracted the win32 console API bindings for setting cursor positions
from ansi-terminal project and put them in Win32ANSI.hs. I had to put
this in a separate file because I had an issue with ghci.  To run this,
I had to compile the console API bindings with ghc first and then run
ghci as follows

 C:\> ghc -c Win32ANSI.hs
 C:\> ghci calculatorWin32.lhs

Without compiling the object code, ghci cannot find the proper link for
win32 console API FFI bindings.

 C:\> ghci calculatorWin32.lhs
GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 3] Compiling Parsing  ( Parsing.lhs, interpreted )
[2 of 3] Compiling Win32ANSI( Win32ANSI.hs, interpreted )

During interactive linking, GHCi couldn't find the following symbol:
  getconsolescreenbufferi...@8
This may be due to you not asking GHCi to load extra object files,
archives or DLLs needed by your current session.  Restart GHCi, specifying
the missing library using the -L/path/to/object/dir and -lmissinglibname
flags, or simply by naming the relevant files on the GHCi command line.
Alternatively, this link failure might indicate a bug in GHCi.
If you suspect the latter, please send a bug report to:
  glasgow-haskell-b...@haskell.org


Is this a bug or a natural behavior of ghci? This is strange to me
since ghci finds the proper link for the functions in the other C
libraries such as getch in conio.h.


In addition, I am attaching a patched calculator.lhs which works
for Unix/Linux on both GHC 6.8.x and GHC 6.10.1. The one currently
on the book homepage only works for GHC 6.8.x but not GHC 6.10.1.
This is due to the bug fix of hSetBuffering in GHC 6.10.1.

To run these calculator example you will also need Parsing.lhs from
the book hompage.http://www.cs.nott.ac.uk/~gmh/Parsing.lhs

--
  Ahn, Ki Yung
Calculator example from section 9.6 of Programming in Haskell,
Graham Hutton, Cambridge University Press, 2007.

Note: the definition for getCh in this example works with the
Glasgow Haskell Compiler, but may not work with some Haskell
systems, such as Hugs.  Moreover, the use of control characters
may not work on some systems, such as WinHugs.

Note: This code works for both GHC versions 6.8.x and 6.10.1 on Unix/Linux.
   Previous code on the webpage only worked on GHC 6.8.x.  -- Ahn, Ki Yung

> import Parsing
> import System.IO

Parser for expressions
--

> expr  :: Parser Int
> expr  =  do t <- term
> do symbol "+"
>e <- expr
>return (t + e)
>  +++ do symbol "-"
> e <- expr
> return (t - e)
>  +++ return t
> 
> term  :: Parser Int
> term  =  do f <- factor
> do symbol "*"
>t <- term
>return (f * t)
>  +++ do symbol "/"
> t <- term
> return (f `div` t)
>  +++ return f
>
> factor:: Parser Int
> factor=  do symbol "("
> e <- expr
> symbol ")"
> return e
>   +++ integer

Derived primitives
--

> getCh :: IO Char
> getCh = do hSetEcho stdin False
>hSetBuffering stdin NoBuffering
>c <- getChar
>hSetEcho stdin True
>hSetBuffering stdin LineBuffering
>return c
>
> beep  :: IO ()
> beep  =  putStr "\BEL"
> 
> cls   :: IO ()
> cls   =  putStr "\ESC[2J"
>
> type Pos  =  (Int,Int)
> 
> goto   

Re: [Haskell-cafe] Type classes vr.s functions

2008-12-20 Thread Luke Palmer
On Sat, Dec 20, 2008 at 6:20 PM, Brian Hurt  wrote:

>
> So, style question for people, if I can.  I have a certain problem-
> basically, I have a bunch of functions which need a special function,
> of type a -> Foo say.  And a bunch of other functions which can define
> that function on some type of interest, and then what to call the first
> batch of functions.  I can do this either by defining a type class,
> something like:
> class Fooable a where
>toFoo :: a -> Foo
> or I can simply have all the functions which need a toFoo take an extra
> agrument.  Performance really isn't that important here, so it's really
> a matter of style- which approach would people prefer in this case?


And it doesn't matter as the performance would be the same in the two cases
also.

My general rule of thumb is to always write combinators first, since they do
not suffer the composability limitations that typeclasses do (rougly
typeclasses perform a proof search which is subject to restrictions to
ensure decidability, whereas with combinators you provide the proof, so
there are no such restrictions).  Then typeclass instances can be trivially
defined in terms of the combinators.  Note that the other way around is not
usually possible.  So eg.:

  module Foo where

  type Fooify a = a -> Foo
  int :: Fooify Int
  int = ...
  list :: Fooify a -> Fooify [a]
  list = ...

  -- then, if determined that this would be convenient
  class Fooable a where
  toFoo :: Fooify a

  instance Fooable Int where toFoo = int
  instance (Fooable a) => Fooable [a] where toFoo = list toFoo
  ...

Luke


>
> Brian
>
> ___
> 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