[Haskell-cafe] Build problems with HDBC-mysql on the Mac

2010-11-22 Thread Martijn van Steenbergen

Dear cafe,

Following the instructions at 
http://matt.freels.name/2010/hdbc-mysql-os-x.html I successfully 
installed HDBC-mysql on my Mac!


However when doing a "cabal install" in a local package which depends on 
HDBC-mysql, cabal proceeds to reinstall HDBC-mysql (is this a bug? see 
my other email from a few moments ago), this time unsuccessfully because 
it is using the unpatched cached version downloaded from hackage. This 
breaks my installation: ghc-pkg list colors the package red.


Now comes the weird part. :-) I try to reinstall HDBC-mysql with my 
unpacked, patched version. It fixes my installation of HDBC-again, even 
though it exits prematurely with some errors! I've included the output 
at the end of this email.


I wonder:

Where do these errors suddenly come from? The first time the 
installation went without trouble.


How come it fixes my installation even though it reports errors?

Thank you in advance,

Martijn.



Output of "cabal install --extra-lib-dirs=/usr/local/lib:" in a local 
version of HDBC-mysql, patched according to 
http://matt.freels.name/2010/hdbc-mysql-os-x.html:


Resolving dependencies...
[1 of 1] Compiling Main ( Setup.lhs, dist/setup/Main.o )

Setup.lhs:8:0:
Warning: In the use of `findProgramOnPath'
 (imported from Distribution.Simple.Program):
 Deprecated: "use findProgramLocation instead"
Linking ./dist/setup/setup ...
Configuring HDBC-mysql-0.6.3...
Preprocessing library HDBC-mysql-0.6.3...
Connection.hsc:23:19: error: mysql.h: No such file or directory
Connection.hsc: In function ‘main’:
Connection.hsc:166: error: ‘MYSQL_FIELD’ undeclared (first use in this 
function)

Connection.hsc:166: error: (Each undeclared identifier is reported only once
Connection.hsc:166: error: for each function it appears in.)
Connection.hsc:170: error: expected specifier-qualifier-list before 
‘MYSQL_FIELD’

Connection.hsc:170: error: expected ‘;’ before ‘)’ token
Connection.hsc:170: error: expected statement before ‘)’ token
Connection.hsc:171: error: expected specifier-qualifier-list before 
‘MYSQL_FIELD’

Connection.hsc:171: error: expected ‘;’ before ‘)’ token
Connection.hsc:171: error: expected statement before ‘)’ token
Connection.hsc:172: error: expected specifier-qualifier-list before 
‘MYSQL_FIELD’

Connection.hsc:172: error: expected ‘;’ before ‘)’ token
Connection.hsc:172: error: expected statement before ‘)’ token
Connection.hsc:173: error: expected specifier-qualifier-list before 
‘MYSQL_FIELD’

Connection.hsc:173: error: expected ‘;’ before ‘)’ token
Connection.hsc:173: error: expected statement before ‘)’ token
Connection.hsc:174: error: expected specifier-qualifier-list before 
‘MYSQL_FIELD’

Connection.hsc:174: error: expected ‘;’ before ‘)’ token
Connection.hsc:174: error: expected statement before ‘)’ token
Connection.hsc:175: error: expected specifier-qualifier-list before 
‘MYSQL_FIELD’

Connection.hsc:175: error: expected ‘;’ before ‘)’ token
Connection.hsc:175: error: expected statement before ‘)’ token
Connection.hsc:203: error: ‘MYSQL_BIND’ undeclared (first use in this 
function)
Connection.hsc:210: error: expected specifier-qualifier-list before 
‘MYSQL_BIND’

Connection.hsc:210: error: expected ‘;’ before ‘)’ token
Connection.hsc:210: error: expected statement before ‘)’ token
Connection.hsc:211: error: expected specifier-qualifier-list before 
‘MYSQL_BIND’

Connection.hsc:211: error: expected ‘;’ before ‘)’ token
Connection.hsc:211: error: expected statement before ‘)’ token
Connection.hsc:212: error: expected specifier-qualifier-list before 
‘MYSQL_BIND’

Connection.hsc:212: error: expected ‘;’ before ‘)’ token
Connection.hsc:212: error: expected statement before ‘)’ token
Connection.hsc:213: error: expected specifier-qualifier-list before 
‘MYSQL_BIND’

Connection.hsc:213: error: expected ‘;’ before ‘)’ token
Connection.hsc:213: error: expected statement before ‘)’ token
Connection.hsc:214: error: expected specifier-qualifier-list before 
‘MYSQL_BIND’

Connection.hsc:214: error: expected ‘;’ before ‘)’ token
Connection.hsc:214: error: expected statement before ‘)’ token
Connection.hsc:215: error: expected specifier-qualifier-list before 
‘MYSQL_BIND’

Connection.hsc:215: error: expected ‘;’ before ‘)’ token
Connection.hsc:215: error: expected statement before ‘)’ token
Connection.hsc:216: error: expected specifier-qualifier-list before 
‘MYSQL_BIND’

Connection.hsc:216: error: expected ‘;’ before ‘)’ token
Connection.hsc:216: error: expected statement before ‘)’ token
Connection.hsc:228: error: ‘MYSQL_TIME’ undeclared (first use in this 
function)
Connection.hsc:232: error: expected specifier-qualifier-list before 
‘MYSQL_TIME’

Connection.hsc:232: error: expected ‘;’ before ‘)’ token
Connection.hsc:232: error: expected statement before ‘)’ token
Connection.hsc:233: error: expected specifier-qualifier-list before 
‘MYSQL_TIME’

Connection.hsc:233: error: expected ‘;’ before ‘)’ token
Connection.hsc:233: error: 

[Haskell-cafe] Why does cabal unnecessarily reinstall dependencies?

2010-11-22 Thread Martijn van Steenbergen

Hello cafe,

When I want to locally install my own package through "cabal install" it 
tries to reinstall dependencies convertible-1.0.9.1, HDBC-2.2.6.1 and 
HDBC-mysql-0.6.3 even though they are already installed (and work fine). 
Why does it do this?


cabal-install version 0.8.2
using version 1.8.0.2 of the Cabal library
Mac OS Leopard

Thanks,

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


Re: [Haskell-cafe] trouble with HDBC-mysql on Mac OS X

2010-11-21 Thread Martijn van Steenbergen
Hi Mark, Chris,

I had trouble as well but just found this pretty recent blog post by @freels
which worked like a charm for me:

http://matt.freels.name/2010/hdbc-mysql-os-x.html

I hope it works for you as well!

I've added Chris to the list of recipients because maybe he can incorporate
the fix directly into the installation process of HDBC-mysql.

Martijn.


On Thu, Feb 11, 2010 at 3:49 AM, Mark Lentczner  wrote:

> I'm having trouble with HDBC-mysql on Mac OS X (10.6, Snow Leopard). It
> compiles and builds fine, but when loaded (into ghci), the dynamic loader
> complains about not being able to find libmygcc.dylib. The issue is, MySQL's
> libmygcc is a static lib, not a dynamic one, so of course it won't find it.
>
> I've checked the build sequence that HDBC-mysql uses, and it calls upon
> mysql_config to generate the lib options. I've checked those and they are
> correct, expressly listing libmygcc statically (!). I've tried building
> against both the 64bit and 32bit versions of MySQL libs. (Suspect that only
> the 32bit should work.)
>
> Anyone have HDBC-mysql running on 10.6? Any ideas for me to try would be
> appreciated.
>
>- Mark
>
>
> Mark Lentczner
> http://www.ozonehouse.com/mark/
> IRC: mtnviewmark
>
>
>
> ___
> 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: [Hackathon] BelHac: A Hackaton in Belgium, 5-7 November

2010-09-27 Thread Martijn van Steenbergen
I have just booked 5 beds in Hostel 47 in Ghent for our group. We will 
be staying in a 6-bed room, so there is still one bed available. If 
anyone is still looking for a bed in Ghent and wants to share a room 
with fellow Haskellers, that one bed might be an interesting choice. I 
told them we were there for BelHac, so if you mention that, they should 
be able to figure out which bed is meant.


Groetjes,

Martijn.


On 7/20/10 15:44, Jasper Van der Jeugt wrote:

We are very pleased to officially announce an international
Hackaton/Get-together in Ghent, Belgium, on 5, 6 and 7 November 2010.

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


Re: [Haskell-cafe] Re: Can we come out of a monad?

2010-08-10 Thread Martijn van Steenbergen

On 8/10/10 23:53, Felipe Lessa wrote:

and the result is "IO Int".  When we "replace the function call by its
result", I think it is fair to replace the C function call by an "int"
and the Haskell function call by an "IO Int", because that is what
those functions return.


Fair enough. :-)

Also, a correction to what I said earlier: it's not C's = that 
corresponds to a bind <-, it's (...args...) that does. I think.


On a side note, imperative languages with first-class 
functions/delegates can express your Haskell example. For example, 
Javascript:


  var x = function() { return randomNumber(10, 15); }
  return x() + x();

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


Re: [Haskell-cafe] Re: Can we come out of a monad?

2010-08-10 Thread Martijn van Steenbergen

On 8/10/10 23:27, Felipe Lessa wrote:

If we had in C:

   return (randomNumber(10, 15) + randomNumber(10, 15))

That would not be the same as:

   int x = randomNumber(10, 15)
   return (x + x)


That's not fair. You're comparing C's '=' with Haskell's '='. But you 
should be comparing C's '=' with Haskell's '<-'.


In your Haskell example, x :: IO Int. In your C example, x :: Int.

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


Re: [Haskell-cafe] Re: Can we come out of a monad?

2010-08-10 Thread Martijn van Steenbergen

On 8/2/10 7:09, Ertugrul Soeylemez wrote:

Given the definition of a Haskell function, Haskell is a pure language.
The notion of a function in other languages is not:

   int randomNumber();

The result of this function is an integer.  You can't replace the
function call by its result without changing the meaning of the program.


I'm not sure this is fair. It's perfectly okay to replace a call 
"randomNumber()" by that method's *body* (1), which is what you argue is 
okay in Haskell.


Martijn.


(1) Modulo some renaming, and modulo the complicated non-compositional 
meanings of control statements such as "return", etc.

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


Re: [Haskell-cafe] Unused import warnings.

2010-08-10 Thread Martijn van Steenbergen
Are you saying that GHC complains about an unused import that is in fact 
used? Perhaps you've run into this bug:

http://hackage.haskell.org/trac/ghc/ticket/1148

Are you using a recent version of GHC?

Groetjes,

Martijn.


On 8/10/10 22:22, Lyndon Maydwell wrote:

Hi Cafe.

I have written some QuickCheck properties in my source and am using
these for testing, however, when I compile my program I get warned
about unused imports:


Warning: Module `Test.QuickCheck' is imported, but nothing from it is used


Is there a way to suppress these warnings for a particular module by
using a pragma directive or something similar?


Thanks!

- Lyndon
___
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] Reverse unification question

2010-08-02 Thread Martijn van Steenbergen

Dear café,

Given:

instance Category C
y :: forall r. C r (A -> r)


I am looking for the types of x and z such that:

x . y :: forall r. C r r
y . z :: forall r. C r r


Can you help me find such types? I suspect only one of them exists.

Less importantly, at least to me at this moment: how do I solve problems 
like these in general?


Thank you,

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


Re: [Haskell-cafe] Can we come out of a monad?

2010-07-30 Thread Martijn van Steenbergen

On 7/30/10 12:29, Tillmann Rendel wrote:

C K Kashyap wrote:

I am of the
understanding that once you into a monad, you cant get out of it?


That's not correct.

There are many monads, including Maybe, [], IO, ... All of these monads
provide operations (>>=), return and fail, and do notation implemented
in terms of these functions, as a common interface. Using just this
common interface, you cannot "get out of the monad".

But most if not all monads also provide additional operations, specific
to the monad in question. Often, these operations can be used to "get
out of that monad". For example, with Maybe, you can use pattern matching:


In fact, I would argue that a monad which you cannot escape from is not 
very useful at all. IO is the only exception I know of.


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


Re: [Haskell-cafe] Can we come out of a monad?

2010-07-30 Thread Martijn van Steenbergen

On 7/30/10 9:29, Stefan Holdermans wrote:

Jason,


There is one case where you can break out of a monad without knowing which 
monad it is.  Well, kind of.  It's cheating in a way because it does force the 
use of the Identity monad.  Even if it's cheating, it's still very clever and 
interesting.


How is this cheating?  Or better, how is this breaking out of a monad "without 
knowing which monad it is"?  It isn't. You know exactly which monad you're breaking 
out: it's the identity monad.  That's what happens if you put quantifiers in negative 
positions: here, you are not escaping out of an arbitrary monad (which you can't), but 
escaping out of a very specific monad.


Also, the only monadic functions the argument may use are return, bind 
and fail. It's hard to do something useful with only those functions.



The specific function is:
  >  purify :: (forall m. Monad m =>  ((a ->  m b) ->  m b)) ->  ((a->b)->b)
  >  purify f = \k ->  runIdentity (f (return . k))


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


Re: [Haskell-cafe] Re: ANN: weighted-regexp-0.1.0.0

2010-07-28 Thread Martijn van Steenbergen

On 7/27/10 9:58, Sebastian Fischer wrote:


On Jul 27, 2010, at 9:15 AM, Sjoerd Visscher wrote:


Oh, by the way, with noMatch, eps, alt and seq_ RegExp is itself a
Semiring,


Yes, but it's hard to define an Eq instance for arbitrary regular
expressions that reflects equivalence of regexps.


How hard is this exactly?

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


Re: [Haskell-cafe] Re: ANN: weighted-regexp-0.1.0.0

2010-07-28 Thread Martijn van Steenbergen

On 7/28/10 14:53, S. Doaitse Swierstra wrote:

see: file:///Users/doaitse/.cabal/share/doc/uu-parsinglib-2.4.2/html/index.html


Readers might have more luck with the following URLs:

http://hackage.haskell.org/package/uu-parsinglib
http://hackage.haskell.org/packages/archive/uu-parsinglib/2.4.2/doc/html/Text-ParserCombinators-UU-README.html

Groetjes,

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


Re: [Haskell-cafe] List manager and duplicate copies of messsages

2010-07-21 Thread Martijn van Steenbergen

On 7/21/10 12:48, José Romildo Malaquias wrote:

Hello.

I have noticed that I do not receive duplicate copies of messages from
haskell-cafe, although "Avoid duplicate copies of messages?" is set to
"No" in the mailing list membership configuration.

I want the copies because I archive all the mailing list messages with
procmail based on the "X-BeenThere" header line.

Has anybody else seen this behaviour, or am I missing anything?

Is there any problems with the mailing list manager?


You're using gmail. See:

http://www.google.com/support/forum/p/gmail/thread?tid=2d5dbc1f28270634

HTH,

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


Re: [Haskell-cafe] Code Example and Haskell Patterns

2010-07-09 Thread Martijn van Steenbergen

On 7/8/10 21:36, Stephen Tetley wrote:

Hello

I suspect you will have to choose single examples for each of the
patterns/ abstractions you are interested in.

Doaitse Swierstra's library UU.Parsing is the originator or the
Applicative style. Its latest incarnation is the library
uu-parsinglib.


Applicative style has several contributors:
* AFAIK, Niklas Röjemo first came up with the names for the operators 
(as the haddock for Control.Applicative says)
* It was used heavily, popularised and expanded by (among others) 
Doaitse Swierstra
* Conor McBride and Ross Paterson recognised the pattern could be 
applied to things other than parsers


(Correct me if I'm wrong!)

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


Re: [Haskell-cafe] Why this doesn't type checked

2010-06-28 Thread Martijn van Steenbergen

On 6/27/10 21:52, Victor Nazarov wrote:
>> class Sizeable sizeable
>>where type Sizeof sizeable
>>  sizeof :: Sizeof sizeable

This is where the type checker should complain. There is no valid way to 
call sizeof, regardless of what instances are available.


The situation is similar to this:

> class C a where x :: Int

In which case the compiler says:

> The class method `x'
> mentions none of the type variables of the class C a
> When checking the class method: x :: Int
> In the class declaration for `C'

I thought there was already a trac ticket for this, but I can't find it 
right now.


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


Re: [Haskell-cafe] parsec: how to get end location

2010-06-14 Thread Martijn van Steenbergen

On 6/14/10 0:10, Roman Cheplyaka wrote:

Of course most parsers don't consume trailing newlines. But I was
writing general function to use in many places in the code which would
recover the end location. In most cases it just subtracts 1 from the
column number, but what if it just happened so that column number is 1?


Parsers can be composed of lots of functions, but eventually all the 
actual consumption of symbols boils down to calls to 
Text.Parsec.Prim.tokenPrimEx. This is where you need to address your 
problem: find the places in your code where this function is called (or 
the derived tokenPrim or token) and intercept there. Hopefully you have 
defined your own 'satisfy' function and need only change that one.


Once you've found those places, there's multiple ways to solve the 
problem. For example, you could keep track of the last interesting 
(=non-whitespace) position. Or you could parse the whitespace in a 
separate phase.


There is no way to retroactively intercept these calls, which I think is 
a flaw in the design of Parsec. It would have been nice to have a 
'runParsecWith myTokenPrimEx', or better yet capture the Parsec 
primitives in a type class.


Groetjes,

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


Re: [Haskell-cafe] learning advanced haskell

2010-06-14 Thread Martijn van Steenbergen

On 6/14/10 10:39, Ivan Lazar Miljenovic wrote:

By being told that using them would solve some problem you're
complaining about on #haskell or the mailing lists, you look at
examples, read up on them, etc.

Short version: don't worry about advanced concepts until you have to.
If all else fails, it doesn't hurt to write out the low-level version
yourself and then get told in a code review that it would be "easier" or
more elegant with an advanced technique.


Exactly this. It's happened a few times now that I ran into a problem 
and then a bit later found out that feature XYZ was exactly what I 
needed. A feature I never understood but now suddenly had a good 
intuition for because it is a (or the) solution to a problem I had been 
thinking about for a while.


But sometimes a feature looks really interesting and you really want to 
run into a problem to which the feature is the solution. If this is the 
case for you with RankNTypes, here is such a problem:


1) What's a type of this function? I say *a* type because there are 
multiple correct answers.



debugWith f = do
  putStrLn (f True)
  putStrLn (f 'c')


Don't ask the compiler to infer the type for you; it won't be able to. 
One of the characteristics of RankNTypes is that the compiler needs you, 
the programmer, to supply the type.


2) What would be a good argument to debugWith?

3) What's one reason the compiler can't infer the type for you?

Hope this helps!

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


Re: [Haskell-cafe] Cabal-install: bus error

2010-05-04 Thread Martijn van Steenbergen

On 5/3/10 23:46, Jason Dagit wrote:

This happened to a co-worker on her mac.  We used gdb to track the bus
errors to the network library.  Once we tracked it down to there, we did
some combination of deleting $HOME/.cabal, building/installing the
latest version of Network and then relinking cabal-install.  I've also
seen these errors with some versions of zlib (but, I think that was on
an old Solaris box that had lots of issues).


I just updated to the newest version and had problems with zlib:


ld: warning: in /opt/local/lib/libz.dylib, file is not of required architecture

(full error below)

The solution was:
# port install zlib +universal

I hope this is of use to someone. :-)

Martijn.



Full error:
(...)
[39 of 40] Compiling Distribution.Client.Install ( 
Distribution/Client/Install.hs, 
dist/build/cabal/cabal-tmp/Distribution/Client/Install.o )
[40 of 40] Compiling Main ( Main.hs, 
dist/build/cabal/cabal-tmp/Main.o )

Linking dist/build/cabal/cabal ...
ld: warning: in /opt/local/lib/libz.dylib, file is not of required 
architecture

Undefined symbols:
  "_deflateEnd", referenced from:
  _deflateEnd$non_lazy_ptr in libHSzlib-0.5.2.0.a(Stream.o)
  "_inflateEnd", referenced from:
  _inflateEnd$non_lazy_ptr in libHSzlib-0.5.2.0.a(Stream.o)
  "_inflateInit2_", referenced from:
  _s4ug_info in libHSzlib-0.5.2.0.a(Stream.o)
  "_deflate", referenced from:
  _s4lq_info in libHSzlib-0.5.2.0.a(Stream.o)
  "_deflateInit2_", referenced from:
  _s4z5_info in libHSzlib-0.5.2.0.a(Stream.o)
  "_zlibVersion", referenced from:
  _r336_info in libHSzlib-0.5.2.0.a(Stream.o)
  "_inflate", referenced from:
  _s4om_info in libHSzlib-0.5.2.0.a(Stream.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
cabal: Error: some packages failed to install:
cabal-install-0.8.2 failed during the building phase. The exception was:
exit: ExitFailure 1
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Weird behaviour with positional parameters in HDBC-mysql

2010-04-17 Thread Martijn van Steenbergen

Thanks! That's great news. Yes, all seems fine now. :-)

It was a very interesting bug to isolate. At one point I was in the 
situation where compiling with -O2 fixed the problem and -O0 didn't, 
seemingly consistently.


By the way, I got two warnings while compiling:
* Warning: Fields of `Types.Statement' not initialised: Types.executeRaw
* Pattern match(es) are non-exhaustive in the definition of `bindOfSqlValue'

Thank you again,

Martijn.


On 4/17/10 6:37, Chris Waterson wrote:

I think that this should be fixed with the latest version of the driver (0.6.2).  I was incorrectly 
squirreling away pointers that I'd acquired using "with" or "withCString".  
This worked -- sometimes. :)


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


Re: [Haskell-cafe] Re: Seeking advice about monadic traversal functions

2010-04-08 Thread Martijn van Steenbergen

On 4/6/10 15:31, Heinrich Apfelmus wrote:

In fact, it doesn't actually work for monads, I think you have to wrap
it in a newtype. :D The same effect can be achieved with `ap` , though:


Fortunately, by now most (standard) monads are also applicatives. :-)

Besides generalizing to an arbitrary number of arguments, it uses infix 
operators which saves you some parentheses.


Groetjes,

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


[Haskell-cafe] Weird behaviour with positional parameters in HDBC-mysql

2010-04-07 Thread Martijn van Steenbergen

Dear café (CC John and Chris),

I'm having some trouble with getting positional parameters in HDBC-mysql 
to work. Most of the time they work fine, but sometimes (and often 
enough that it's a serious bother) the parameters don't reach the server 
correctly.


Let me first describe my setup:
* Ubuntu 8.10 intrepid (inside VMWare Fusion on Mac OS X Snow Leopard)
* mysql  Ver 14.12 Distrib 5.0.67, for debian-linux-gnu (i486) using 
readline 5.2

* ghc 6.10.3
* HDBC-2.2.4
* HDBC-mysql-0.6.1

I have a database with a single, empty table:


CREATE TABLE `foo` (
  `id` int(11) NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1031 DEFAULT CHARSET=latin1


And I have the following Haskell program:


import Database.HDBC
import Database.HDBC.MySQL
import Data.List
import Data.Traversable
import Control.Monad

main :: IO ()
main = do
  conn <- connectMySQL defaultMySQLConnectInfo
{ mysqlUnixSocket = "/var/run/mysqld/mysqld.sock"
, mysqlUser = "root"
, mysqlDatabase = "db"
}
  for [1..1000] $ \n -> do
let sql = "select id from foo where id in ("
  ++ intercalate "," (replicate (fromInteger n) "?") ++ ")"
stmt <- prepare conn sql
execute stmt (map SqlInteger [1..n])
finish stmt
  return ()


The program produces no output. All 1000 queries that are sent to the 
database are expected to return 0 results, since table foo is empty. 
This is all fine.


The problem is in the queries that the server receives. If I turn on 
full logging, I expect all queries to have a "where id in (...)" where 
there is an increasing list of integers within the parentheses. But when 
examining the logs, some are small negative numbers, NULLs or just other 
numbers:



506 Execute [980] select id from foo where id in
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,
27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,824,825,826,827,828,829,
830,831,832,833,834,835,836,837,838,839,840,841,842,843,844,845,846,847,
848,849,850,851,852,853,854,855,856,857,858,859,860,861,862,863,864,865,
866,867,868,869,870,871,872,873,874,875,876,877,878,879,880,881,882,883,
884,885,886,887,888,889,890,891,892,893,894,895,896,897,898,899,900,901,
902,903,904,905,906,907,908,0,0,34359738368,-5210566582833489576,NULL,
NULL,0,34359738368,-5210565758199768552,NULL,NULL,0,34359738368,
-5210564933566047528,NULL,NULL,0,34359738368,-5210564108932326504,NULL,
NULL,0,34359738368,-5210563284298605480,NULL,NULL,0,34359738368,
-5210562459664884456,NULL,NULL,158,159,160,161,162,(snip)


The server then faithfully executes the statement and returns the 
results expected for the query it reports to have received, which (in a 
table with actual data) is not what the Haskell program was expecting.


If I compile the program once, the results vary per run.
If I don't use positional parameters but instead render the full SQL 
query myself, there is no problem.


Is this a problem in HDBC or in HDBC-mysql?
What's going on here? How do I fix or work around this?

Many thanks,

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


Re: [Haskell-cafe] Hackage accounts and real names

2010-04-05 Thread Martijn van Steenbergen

+1 for lifting this restriction.

On 4/4/10 23:28, David House wrote:

An issue came up on #haskell recently with Hackage accounts requiring
real names.

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


Re: [Haskell-cafe] Re: Seeking advice about monadic traversal functions

2010-04-02 Thread Martijn van Steenbergen

On 3/31/10 12:44, Heinrich Apfelmus wrote:

 go Next (Single x t1) = liftM (Single x) (rewrite f t1)
 go Next (Fork t1 t2 ) = liftM2 Fork (rewrite f t1)
 (rewrite f t2)

In particular,  liftM  and  liftM2  make it apparent that we're just
wrapping the result in a constructor.


A small remark: I prefer using applicative notation for this:


go Next (Single x t1) = Single x <$> rewrite f t1
go Next (Fork t1 t2 ) = Fork <$> rewrite f t1 <*> rewrite f t2


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


Re: [Haskell-cafe] more thoughts on "Finally tagless"

2010-03-09 Thread Martijn van Steenbergen

Tom Schrijvers wrote:

data EvalDict sem = EvalDict { val :: Int -> sem Int, add :: sem Int
-> sem Int -> sem Int }


An alternative option is to capture the structure in a GADT:


data Eval a where
  Val :: Int -> Eval Int
  Add :: Eval Int -> Eval Int -> Eval Int


And then write what were instances before as functions Eval a -> whatever.

Of course, this makes it harder to combine multiple models.

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


Re: [Haskell-cafe] Notes on migrating from uvector to vector

2010-02-16 Thread Martijn van Steenbergen

Ivan Miljenovic wrote:

On 16 February 2010 08:35, Don Stewart  wrote:

Enjoy the new decade of flexible, fusible, fast arrays for Haskell!


/me points out that 2010 is actually the last year of the decade, and
not the first year of a new decade...


There certainly is /a/ decade that starts today. :-)

Martijn.

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


Re: [Haskell-cafe] Re: Generating repeatable arbitrary values with QuickCheck 2

2010-02-05 Thread Martijn van Steenbergen

Ryan Ingram wrote:

Unfortunately, this makes things like

 infinite_xs <- sequence (repeat arbitrary)

no longer work, since the state never comes out the other side.


You're asking to execute an infinite number of monadic actions. How can 
this ever terminate at all?


Martijn.

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


Re: [Haskell-cafe] functional references and HList?

2010-02-04 Thread Martijn van Steenbergen

Edward Kmett wrote:
Functional references let you both read and write 'attributes' in a 
structure. These can be chained to access members of members.


You can also use them to build bidirectional views on fields (and 
compose those again as well).


Martijn.

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


Re: [Haskell-cafe] Re: Declarative binary protocols

2010-01-19 Thread Martijn van Steenbergen

Antoine Latter wrote:

getResponse = do
  require 256
  x <- getX
  len <- getWord16be
  y <- getY
  z <- getZ
  require (fromIntegral len * 8)
  a <- getA
  b <- getB
  return $ Response x y z a b c


This looks like code that could be written in applicative style, in 
which case you could analyze the parser and automatically compute how 
many bytes are needed, removing the need for explicit calls to require.


Groetjes,

Martijn.

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


[Haskell-cafe] Visualizing function application

2010-01-15 Thread Martijn van Steenbergen

Dear café,

I am deeply impressed with Vacuum[1][2], Ubigraph[3] and especially 
their combination[4]. I can trivially and beautifully visualize the ASTs 
that my parser produces. I can visualize zippers of the ASTs and confirm 
that sharing is optimal.


Ubigraph is also able to animate graph *mutations*, as shown by the 
various demos on Ubigraph's website. How cool would it be if we could 
tell vacuum-ubigraph: here, show this tree, and then show how the tree 
changes when we apply this function on it. We could see how [1,2,3] is 
transformed into a ring when cycle is applied on it, or we could see how 
a list is consumed node by node when a foldr is applied.


I have no idea how difficult this is or how to begin, so I thought I'd 
throw the idea out here. Perhaps it is appealing enough that someone 
picks it up and implements it. :-)


Martijn.


[1] http://hackage.haskell.org/package/vacuum
[2] http://www.youtube.com/watch?v=oujaqo9GAmA
[3] http://ubietylab.net/ubigraph/content/Demos/index.html
[4] http://hackage.haskell.org/package/vacuum-ubigraph
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Language simplicity

2010-01-14 Thread Martijn van Steenbergen

Niklas Broberg wrote:

Haskell '98 apparently features 25 reserved words. (Not counting "forall"
and "mdo" and so on, which AFAIK are not in Haskell '98.)


21 actually. case, class, data, default, deriving, do, else, if,
import, in, infix, infixl, infixr, instance, let, module, newtype, of,
then, type, where. There's also three special words that can still be
used as identifiers, so aren't reserved: as, qualified, hiding.


Since you can define operators in Haskell, would it make sense to 
include '=', '--', ':', ',' etc. as "reserved names" since those can't 
be used as operator names?



Illegal binding of built-in syntax: :
Illegal binding of built-in syntax: (,)
parse error (possibly incorrect indentation)


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


Re: [Haskell-cafe] mtl and transformers

2010-01-11 Thread Martijn van Steenbergen

Günther Schmidt wrote:

Hi,

when I cabal-installed the iteratee package, the transformers package 
was also installed as a dependency.


Now when I run applications that import Control.Monad.Transformers I get 
this:


Could not find module `Control.Monad.Trans':
 it was found in multiple packages: transformers-0.1.4.0 mtl-1.1.0.2


Another solution is to build your applications using Cabal and specify 
your dependency on mtl in the cabal file.


HTH,

Martijn.

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


Re: [Haskell-cafe] suffix or operands invalid for `push'

2009-12-29 Thread Martijn van Steenbergen

Gregory Collins wrote:

Martijn van Steenbergen  writes:


Hello,

Above error is one of those that appear when using GHC on the 64-bit Snow
Leopard. I've already patched my /usr/bin/ghc to mention -optc-m32 -opta-m32
-optl-m32. However, the error still occurs when doing 'cabal haddock' in *some*
packages.

For example, a local project of mine builds just fine, but trying to cabal
haddock the happstack-helpers package goes horribly wrong and no documentation
is generated.

How do I fix this? And why does it happen only in certain packages?


Did you patch hsc2hs also?


I hadn't done that yet, but I've changed it so that the last line now reads:

exec 
/Library/Frameworks/GHC.framework/Versions/610/usr/lib/ghc-6.10.4/hsc2hs 
$tflag $HSC2HS_EXTRA -optc-m32 -opta-m32 -optl-m32 ${1+"$@"} "$Iflag"


However, cabal haddock still reports errors.

Martijn.

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


[Haskell-cafe] suffix or operands invalid for `push'

2009-12-29 Thread Martijn van Steenbergen

Hello,

Above error is one of those that appear when using GHC on the 64-bit 
Snow Leopard. I've already patched my /usr/bin/ghc to mention -optc-m32 
-opta-m32 -optl-m32. However, the error still occurs when doing 'cabal 
haddock' in *some* packages.


For example, a local project of mine builds just fine, but trying to 
cabal haddock the happstack-helpers package goes horribly wrong and no 
documentation is generated.


How do I fix this? And why does it happen only in certain packages?

Many thanks,

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


Re: [Haskell-cafe] Children elements with HXT

2009-12-23 Thread Martijn van Steenbergen

Max Cantor wrote:

That stuffed me up for a bit.  I wrote some ugly template haskell a while back 
to automatically generate XmlPickler instances. can send to you if you want


I recall typLAB writing about generic XML picklers:
   http://blog.typlab.com/2009/11/writing-a-generic-xml-pickler/

They mention package regular-xmlpickler:
   http://hackage.haskell.org/package/regular-xmlpickler

HTH,

Martijn.

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


Re: [Haskell-cafe] What is the rank of a polymorphic type?

2009-12-05 Thread Martijn van Steenbergen

Eugene Kirpichov wrote:

Hello.

Consider the type: (forall a . a) -> String.

On one hand, it is rank-2 polymorphic, because it abstracts over a
rank-1 polymorphic type.
On the other hand, it is monomorphic because it isn't actually
quantified itself: in my intuitive view, a parametrically polymorphic
type has infinitely many instantiations (for example, Int -> Int is an
instantiation of forall a . a -> a, and String -> String also is), and
this type doesn't have any instantiations at all.

Which is correct? Is there really a contradiction? What is the
definition of rank of a polymorphic type?


There's a nice paper about this:

Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich and Mark Shields
"Practical type inference for arbitrary-rank types"
http://research.microsoft.com/en-us/um/people/simonpj/papers/higher-rank/putting.pdf

Section 3.1 of that paper defines what rank types have: "The rank of a 
type describes the depth at which universal quantifiers appear 
contravariantly"


Looking at the examples that are then given I'd say your example has 
rank 2 (but I'm no expert). It only mentions the depth of the forall, 
not whether it has any instantiations.


HTH,

Martijn.

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


Re: [Haskell-cafe] Re: From function over expression (+, *) derive function over expression (+)

2009-12-05 Thread Martijn van Steenbergen

Radek Micek wrote:

Hi,

thank you for your reply but your MulExpr
does not support expressions like

(2*3)+5


Oh! You're right, how silly of me.

Martijn.

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


Re: [Haskell-cafe] From function over expression (+, *) derive function over expression (+)

2009-12-04 Thread Martijn van Steenbergen

Hi Radek,

Radek Micek wrote:

I can write a function to simplify the first expression:

simplify :: Expr -> Expr
simplify = {- replaces:
"a*1" and "1*a" by "a",
"a+0" and "0+a" by a -}

And I would like to use the function simplify for the second type
AExpr. What can I do is to convert AExpr to Expr, simplify it and
convert it back. But I don't like this solution because
conversions take some time.


Like Luke said, you can probably work out something using explicit fixed 
points.


Or you can "cheat" a little and use generic programming:


{-# LANGUAGE DeriveDataTypeable #-}

import Data.Generics

data AddExpr = Const Int | Add AddExpr AddExpr
  deriving (Eq, Show, Typeable, Data)

data MulExpr = AddMul AddExpr | Mul MulExpr MulExpr
  deriving (Eq, Show, Typeable, Data)


Here you have explicitly encoded MulExpr as an extension of AddExpr 
through the constructor AddMul, just like you asked.


Now we define the simplification steps you mentioned, one for each 
datatype. They perform only one simplification step instead of calling 
themselves recursively. The type of simplifyAddStep ensures that it 
doesn't accidentally introduce multiplications:



simplifyAddStep :: AddExpr -> AddExpr
simplifyAddStep expr = case expr of
  Add (Const 0) y -> y
  Add x (Const 0) -> x
  _   -> expr

simplifyMulStep :: MulExpr -> MulExpr
simplifyMulStep expr = case expr of
  Mul (AddMul (Const 1)) x -> x
  Mul x (AddMul (Const 1)) -> x
  _ -> expr


Using generic programming, we can combine these two steps and apply them 
recursively on entire trees, bottom-up:



simplify :: Data a => a -> a
simplify = everywhere (id `extT` simplifyAddStep `extT` simplifyMulStep)


An example invocation:


*Main> simplify (AddMul (Const 1) `Mul` (AddMul (Const 2 `Add` Const 0)))
AddMul (Const 2)


Hope this helps,

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


Re: [Haskell-cafe] From function over expression (+, *) derive function over expression (+)

2009-12-04 Thread Martijn van Steenbergen

Luke Palmer wrote:

On Fri, Dec 4, 2009 at 10:26 AM, Radek Micek  wrote:

Hello.

I have two types for expression:

data Expr = Add Expr Expr | Mul Expr Expr | Const Int

data AExpr = AAdd AExpr AExpr | AConst Int

The first one supports addition and multiplication and the second
only addition.

I can write a function to simplify the first expression:

simplify :: Expr -> Expr
simplify = {- replaces:
"a*1" and "1*a" by "a",
"a+0" and "0+a" by a -}

And I would like to use the function simplify for the second type
AExpr. What can I do is to convert AExpr to Expr, simplify it and
convert it back. But I don't like this solution because
conversions take some time.


Well there are more involved reasons than simply the conversion taking
time.  If you would like the type system on your side, you have a
decent modeling problem on your hands.  How can you guarantee that
simplify will return a type that will "fit" in AExpr?  Simplify might
turn "a+a" into "2*a", and then your trick no longer works.  It would
seem that you need to typecheck the function twice.

You could attempt to go the other way, i.e. define a simplify on AExpr
and map to and from Expr, but that will have trouble with expressions
like 0+(2*a), because 2*a has no representation in AExpr.

My hunch is that to do this "properly", you need to use some of the
fixed point modeling that I can't find the paper about (!)  (It's
popular, someone please chime in :-).  I.e. define a data type which,
directed by type classes, may or may not support multiplication.  Then
define separately an additive simplifier and a multiplicative
simplifier on that.


Perhaps you're looking for:

Wouter Swierstra
Data types à la carte
http://www.cse.chalmers.se/~wouter/Publications/DataTypesALaCarte.pdf

Groetjes,

Martijn.

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


Re: [Haskell-cafe] Finding HP

2009-12-04 Thread Martijn van Steenbergen

Don Stewart wrote:

vandijk.roel:

On Wed, Dec 2, 2009 at 11:44 PM, Gregory Crosswhite
 wrote:

On a more serious note, "Download Haskell" /= "Download Haskell Platform", so if I were glancing 
down the sidebar looking for a link to download the "Haskell Platform" then the first link wouldn't have 
registered for me.  And putting a "X has been released link!" in the news does not count as a prominent 
download link.

If I wanted to know something *about* the *Haskell Platform* I would
click the link The Haskell Platform under the section About. So it is
actually mentioned 3 times on the front page. What could be improved
are the 2 download links: "Download Haskell" and "Download GHC". It
would perhaps be better to have one nice big "Download" button that
takes you to a separate download page.


Having a single download link that only points to the Haskell Platform
would be a bit of a policy shift. Is the community ready to accept that
users looking for "Haskell" should be given the HP binaries?


Although as others pointed out this wasn't the suggestion, I do think 
that it is a good idea to eventually have a single big download button à 
la firefox.com: Haskell Platform OS-specific (based on best effort 
guess) button linking directly to download, with less prominent options 
to download for other OS'es, or other implementations.


Groetjes,

Martijn.

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


[Haskell-cafe] Implicit newtype unwrapping

2009-12-02 Thread Martijn van Steenbergen

So here's a totally wild idea Sjoerd and I came up with.

What if newtypes were unwrapped implicitly?

What advantages and disadvantages would it have?
In what cases would this lead to ambiguous code?

Thanks,

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


Re: [Haskell-cafe] Type synonym family inside type class

2009-11-27 Thread Martijn van Steenbergen

Hi Sean,

Sean Leather wrote:
Perhaps this isn't answering your question, but you can turn the above 
into an associated type as follows.


class MkErrorAlg f where
  type ErrorAlg (f :: (* -> *) -> * -> *) :: * -> * -> *
  mkErrorAlg :: ErrorAlg f e a -> f (K0 a) ix -> Either e a


That is true. But how would you translate the following instance to the 
new version?



type instance ErrorAlg (K b   :*: f)  e a = b  -> ErrorAlg f e a


I don't know how to do that without introducing a new newtype that I can 
partially parametrize. I don't want to have to introduce a newtype for 
that, especially because it defeats the purpose of (in this specific 
case) generically deriving a user-friendly type.


Groetjes,

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


Re: [Haskell-cafe] I really donot know how to use `newtype` ?

2009-11-27 Thread Martijn van Steenbergen

zaxis wrote:

then how to use `X` ?  Would you mind explaining the newtype X in detail ?


You can just think of a newtype as a normal datatype:


data X a = X (ReaderT XConf (StateT XState IO) a)


I.e. construction and pattern matching work indentically.

Every newtype you will find will have exactly one constructor with 
exactly one field. Only datatypes that have one constructor with one 
field can be made newtypes.


You can only use generalized deriving on newtypes:
http://www.haskell.org/ghc/docs/6.10-latest/html/users_guide/deriving.html

There are some other differences between datatypes and newtypes which 
are only sometimes important. They are to do with efficiency and bottom. 
You can read about them here:


http://www.haskell.org/tutorial/moretypes.html

HTH,

Martijn.

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


Re: [Haskell-cafe] namespaces for values, types, and classes

2009-11-27 Thread Martijn van Steenbergen

Sebastian Fischer wrote:
Does anyone know why types and values are in separate namespaces but 
classes and types are not?


Good question. I don't know the answer, but it is interesting to note 
that the report explicitly mentions this decision (but provides no reason):


"An identifier must not be used as the name of a type constructor and a 
class in the same scope."


http://www.haskell.org/onlinereport/intro.html

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


[Haskell-cafe] Type synonym family inside type class

2009-11-27 Thread Martijn van Steenbergen

Hello,

I have a type family and a type class:


type family ErrorAlg (f :: (* -> *) -> * -> *) e ix :: *



class MkErrorAlg f where
  mkErrorAlg :: ErrorAlg f e a -> f (K0 a) ix -> Either e a


Instances for these two really go hand in hand, so I thought I would 
move the type family into the type class. However, this causes GHC to 
complain about the type variables that are bound on the LHS of the type 
synonym:



Not in scope: type variable `e'
Not in scope: type variable `ix'


In function types, using new type variables (i.e. type variables not 
bound by the type class header) implicitly means universal 
quantification over these variables. Why is this disallowed in type 
families inside type classes?


Thanks,

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


Re: [Haskell-cafe] Pointfree rank-2 typed function

2009-11-24 Thread Martijn van Steenbergen

Simon Peyton-Jones wrote:

It used to be, because GHC used to implement so-called "deep skolemisation".  
See Section 4.6.2 of
http://research.microsoft.com/en-us/um/people/simonpj/papers/higher-rank/putting.pdf

Deep skolemisation was an unfortunate casualty of the push to add impredicative polymoprhism.  However, as I mentioned in an earlier email, I'm currently planning to take impredicative polymorphism *out*, which means that deep skolemisation might come back *in*. 


Are there workarounds for uses of impredicative types, or do we lose the 
ability to express certain programs as a result?


Thanks,

Martijn.

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


[Haskell-cafe] Kind polymorphism

2009-11-23 Thread Martijn van Steenbergen

Hello,

Are there currently any known problems that would hinder the 
implementation of kind polymorphism [1], e.g. unresolved inelegancies or 
technical limitations, or is it only a matter of finding the time to 
implement it?


Thanks,

Martijn.


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


Re: [Haskell-cafe] Working with multiple projects

2009-11-11 Thread Martijn van Steenbergen

Tony Morris wrote:

I have two projects that I intend to put on hackage soon. One depends
on the other. I have "cabaled" both. I am wondering how others work
with this kind of set up where changes are made to both libraries as
they work.


You just update and re-upload the packages as necessary. It really helps 
here if you follow the versioning guidelines:


http://www.haskell.org/haskellwiki/Package_versioning_policy

HTH,

Martijn.

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


Re: [Haskell-cafe] Fair diagonals

2009-11-06 Thread Martijn van Steenbergen

Henning Thielemann wrote:


On Wed, 4 Nov 2009, Sjoerd Visscher wrote:



On Nov 4, 2009, at 3:21 PM, Twan van Laarhoven wrote:

  I looked on hackage but I was surprised that I couldn't find 
this simple
  monad. The package level-monad does look very similar, only it 
uses a

  different list type for the representation.


indeed, level-monad works as well:

import Control.Monad.Levels
import Data.FMList (fromList)

diagN = bfs . mapM fromList


Can someone explain the difference between control-monad-omega and 
level-monad?


So from what I understand this is the difference:

Omega is biased towards the lower dimensions while Levels
treats all dimensions equally, or at least more equally. You can 
formalize the latter by saying: the sums of the indices should be 
non-decreasing.


From Omega's documentation I understand this is on purpose:

"(...) Likewise, a breadth-first search of a data structure can fall 
short if it has an infinitely branching node. Omega addresses this 
problem by using a "diagonal" traversal that gracefully dissolves such 
data."


However, I can't verify this:

 runOmega . mapM each $ map (:[]) [1..]
*** Exception: stack overflow


Or maybe I misunderstood Omega's documentation.

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


[Haskell-cafe] Re: Fair diagonals

2009-11-04 Thread Martijn van Steenbergen

Louis Wasserman wrote:

+1 on Control.Monad.Omega.  In point of fact, your diagN function is simply

diagN = runOmega . mapM Omega

You'll find it an interesting exercise to grok the source of 
Control.Monad.Omega, obviously, but essentially, you're replacing 
concatMap with a fair (diagonal) traversal order version.


Thanks for the replies!

I've looked at Omega but it's not fair enough. The sums of the indices 
are not non-decreasing:


map sum $ runOmega . mapM each $ [[1..], [1..], [1..]]
[3,4,4,4,5,5,5,5,6,6,5,6,6,7,7,5,6,7,7,8,8,6,6,7,8,8,9,9,6,7,...

Is there another way to use Omega that meets this (very important) 
criterion or is Omega not the right tool here?


Thanks,

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


[Haskell-cafe] Fair diagonals

2009-11-03 Thread Martijn van Steenbergen

Dear café,

I am looking for a function that does an N-dimensional diagonal 
traversal. I want the traversal to be fair: the sum of the indices of 
the produced combinations should be non-decreasing. Let me illustrate 
with an example.


The type of a 2-dimensional traversal would look like this:

diag2 :: [a] -> [b] -> [(a, b)]


The first two arguments are the two half-axes of the grid and the result 
is a fair diagonal traversal of all the points. For example:

diag2 [1,2,3] [4,5,6,7]

[(1,4),(2,4),(1,5),(3,4),(1,6),(2,5),(1,7),(3,5),(2,6),(2,7),(3,6),(3,7)]


Of course the function should work on infinite lists:

diag2 [1..] [1..]

[(1,1),(2,1),(1,2),(3,1),...


Or a combination of finite and infinite lists:

diag2 [1,2] [1..]

[(1,1),(2,1),(1,2),(1,3),(2,2),(1,4),...


Notice that in each case the sum of the pairs (which can seen as indices 
in these particular examples) are non-decreasing:

let sums = map (uncurry (+))
sums $ diag2 [1,2,3] [4,5,6,7]

[5,6,6,7,7,7,8,8,8,9,9,10]

sums $ diag2 [1..] [1..]

[2,3,3,4,4,4,5,5,5,5,6,...

sums $ diag2 [1,2] [1..]

[2,3,3,4,4,5,5,6,6,7,7,...


Similarly for 3 dimensions the type would be:

diag3 :: [a] -> [b] -> [c] -> [(a, b, c)]


For N dimensions we have to sacrifice some generality and ask all axes 
to be of the same type and produce lists instead of tuples, but I'm 
perfectly happy with that:

diagN :: [[a]] -> [[a]]


I have implemented diag2 and diag3 [1] but noticed that the function 
bodies increase in size exponentially following Pascal's triangle and 
have no clue how to generialize to N dimensions. Can you help me write 
diagN?


Bonus points for the following:
* An infinite number of singleton axes produces [origin] (and finishes 
computing), e.g. forall (infinite) xs. diagN (map (:[]) xs) == map (:[]) xs
* For equal indices, the traversal biases to axes that are occur early 
in the input (but I don't know how to formalize this).

* The implementation shows regularity and elegance.

Many thanks,

Martijn.

[1] http://hpaste.org/fastcgi/hpaste.fcgi/view?id=11515
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] uu-parsinglib pKeyword

2009-10-30 Thread Martijn van Steenbergen

Hi Ozgur,

Ozgur Akgun wrote:

pKeyword_Int = ( \ _ _ _ -> "int" ) <$> pSym 'i' <*> pSym 'n' <*> pSym 't'
pKeyword_Float = ( \ _ _ _ _ _ -> "float" ) <$> pSym 'f' <*> pSym 'l' 
<*> pSym 'o' <*> pSym 'a' <*> pSym 't'


As you can see there is an obvious pattern if you try to capture a 
"keyword". If there were a function called pKeyword taking a string as 
an argument and producing the necessary parser, things would be easier.


I think pToken in Text.ParserCombinators.UU.Derived does what you want.

Groetjes,

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


Re: [Haskell-cafe] Applicative but not Monad

2009-10-30 Thread Martijn van Steenbergen

Yusaku Hashimoto wrote:

Hello cafe,
Do you know any data-type which is Applicative but not Monad?


The Except datatype defined in the Applicative paper.

Some parsers are not monads, allowing for optimizations.

Martijn.

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


Re: [Haskell-cafe] How to fulfill the "code-reuse" destiny of OOP?

2009-10-30 Thread Martijn van Steenbergen

Magnus Therning wrote:

IIRC James Gosling once said that if he were to design Java today he would
leave out classes.  I suppose partly due to many of the issues with "data
inheritance".


This sounds interesting. Can you link us to an article, please?

Thanks,

Martijn.

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


[Haskell-cafe] ANN: HoleyMonoid-0.1

2009-10-26 Thread Martijn van Steenbergen

Hello!

I'm happy to announce the first release of HoleyMonoid, a datatype that 
helps you build monoids with holes in them. The holes are filled in 
later using normal function application. For example:



 > let holey = now "x = "
 . later show
 . now ", y = "
 . later show
 > run holey 3 5
 "x = 3, y = 5"


The library is available on Hackage:
   http://hackage.haskell.org/package/HoleyMonoid

Thanks to David Menendez for the name and Sjoerd Visscher for help with 
rewriting and simplifying. :-)


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


Re: [Haskell-cafe] Re: ANN: haskell-src-exts-1.2.0

2009-10-23 Thread Martijn van Steenbergen

Niklas Broberg wrote:

Actually, it seems something went awry. I got a 500 Internal Server
Error on my cabal upload, the package is there on hackage but it seems
it was never added to the list of packages. This means cabal update
doesn't know about it, nor is it listed on the What's New page. Anyone
know what's up with that, and how it can be fixed?


I have exactly the same problem with the package I uploaded tonight. I 
sent Don and Duncan an email but I don't know whether they are the right 
people to bother.


Martijn.

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


Re: [Haskell-cafe] What's this pattern called?

2009-10-23 Thread Martijn van Steenbergen

Thanks for all the pointers, guys. You've been very helpful.

I also found Type-indexed data types (Hinze et al) to be a good source.

Much appreciated!

Martijn.


Martijn van Steenbergen wrote:

data ExprF r


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


Re: [Haskell-cafe] why cannot i get the value of a IORef variable ?

2009-10-23 Thread Martijn van Steenbergen

Anton van Straaten wrote:

On the plus side, this does make for a slogan with high market appeal:

   Haskell: Kittens inside


Thanks. Now I have trouble getting this image of lambda-shaped bonsai 
kittens out of my head.


;-)

Martijn.

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


Re: [Haskell-cafe] Is there in Haskell the eval function?

2009-10-22 Thread Martijn van Steenbergen

Waldemar Biernacki wrote:
Is there the eval function like in imperative languages? 


You mean like in interpreted languages?


I'd like to write an application which has to be compiled to exec file. It is 
neccessary to performe some additional procedures which are unknown at the 
moment of the compilition.


You could use the GHC libraries, or Hint which is built on top of GHC. 
I've used it before and it works pretty nicely.


http://hackage.haskell.org/package/hint

HTH,

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


[Haskell-cafe] What's this pattern called?

2009-10-22 Thread Martijn van Steenbergen

Bonjour café,


data ExprF r
  =  Add  r  r
  |  Sub  r  r
  |  Mul  r  r
  |  Div  r  r
  |  Num  Int


This is a well-known pattern that for example allows nice notation of 
morphisms. But what is it called? I've heard fixed-point view, open 
datatypes and some others, but I'm curious where this pattern comes up 
in literature and what it is called there.


Thanks,

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


Re: [Haskell-cafe] Test cases for type inference

2009-10-21 Thread Martijn van Steenbergen

Peter Verswyvelen wrote:

For learning, I would like to develop my own implementation of type
inference, based on the paper "Typing Haskell in Haskell".

At first sight, the source code of THIH contains a small number of
tests, but I was wandering if a large test set exist?


I'm pretty sure GHC maintains a large set of test cases. Maybe you can 
use some of those?


Or maybe you can just pick a random project from hackage and run your 
type checker on that?


Martijn.

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


Re: [Haskell-cafe] GHC devs

2009-10-15 Thread Martijn van Steenbergen

David Virebayre wrote:

Taking the opportunity to thank very much both Simons and Ian for the
work they do and the enthusiasm they show. You guys rock.


I heartily second that!

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


Re: [Haskell-cafe] newtype deriving Alternative

2009-10-14 Thread Martijn van Steenbergen

It doesn't work for this one:


newtype Split a = Split { runSplit :: [Either a (Char, Split a) ]}


But my handwritten instance remains identical.

Groetjes,

Martijn.

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


Re: [Haskell-cafe] newtype deriving Alternative

2009-10-14 Thread Martijn van Steenbergen

You guys are right. I was being silly. Thanks. :-)

Ryan Ingram wrote:

Works for me on GHC6.10.4:


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


[Haskell-cafe] newtype deriving Alternative

2009-10-14 Thread Martijn van Steenbergen

Hello café,

I've never written an Alternative instance for a newtype yet that 
doesn't look like this:



instance Alternative T where
  empty = T empty
  T x <|> T y = T (x <|> y)


Why does newtype deriving not work for Alternative? (It works fine for 
Monoid.)


Thanks,

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


[Haskell-cafe] Monotype error

2009-10-14 Thread Martijn van Steenbergen

Dear café,


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

type Void = forall a. a

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

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


Compiling this with GHC results in:


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


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

Thanks!

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


Re: [Haskell-cafe] MTL vs Transformers?

2009-10-13 Thread Martijn van Steenbergen

Erik de Castro Lopo wrote:

However after reading the hackage descriptions of both Transformers and
MTL, it seems that they share a very similar heritage. I therefore hacked
the iteratee.cabal file and replaced the build-depends on transformers
with one on mtl and the package built quite happily. I'll play with it
a bit to see if its working correctly.


I think the standard solutions are
* use Cabal for your project and/or
* use the PackageImports extension.

HTH,

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


Re: [Haskell-cafe] Parsec bug, or...?

2009-10-12 Thread Martijn van Steenbergen

Brandon S. Allbery KF8NH wrote:
My fix would be to have myPrefixOf require the prefix be terminated in 
whatever way is appropriate (end of input, white space, operator?) 
instead of simply accepting as soon as it gets a prefix match regardless 
of what follows.


Maybe you can use notFollowedBy for this.

HTH,

Martijn.

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


Re: [Haskell-cafe] CBN, CBV, Lazy in the same final tagless framework

2009-10-09 Thread Martijn van Steenbergen

Felipe Lessa wrote:

which unfortunately needs {-# LANGUAGE RecursiveDo #-} or
some ugliness from mfix


But mdo/mfix is awesome! :-(

Martijn.

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


Re: [Haskell-cafe] Non-traversable foldables

2009-10-09 Thread Martijn van Steenbergen

Ross Paterson wrote:

On Fri, Oct 09, 2009 at 04:41:05PM +0200, Martijn van Steenbergen wrote:

Can anyone think of datatypes that are Foldable but not Traversable?


Set


Nice! Thank you all for your answers.

Martijn.

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


[Haskell-cafe] Non-traversable foldables

2009-10-09 Thread Martijn van Steenbergen

Hallo café,

Can anyone think of datatypes that are Foldable but not Traversable?

If not, what is the purpose of having a separate Foldable class?

Thanks,

Martijn.

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


Re: [Haskell-cafe] Any example of concurrent haskell application?

2009-10-09 Thread Martijn van Steenbergen

Daryoush Mehrtash wrote:
I am trying to learn more about concurrent applications in Haskell by 
studying an existing a real application source code.   I would very much 
appreciate if you can recommend an application that you feel has done a 
good job in implementing a real time application in Haskell.


Yogurt[1], a MUD client, uses two threads: one to process input from the 
server and one to process input from the client. It uses an MVar to 
synchronize. All concurrency is located in module Network.Yogurt.Readline.


Custard[2], a MUD server, uses several threads:
* Server, maintaining MUD state
* one that listens for incoming connections
* per client, one that listens for client input
* per client, one that listens for messages from Server
It uses channels and message passing to synchronize. All concurrency is 
located in module Engine.


[1] http://hackage.haskell.org/package/Yogurt
[2] http://code.google.com/p/custard/

Hope this helps,

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


Re: [Haskell-cafe] type inference question

2009-10-08 Thread Martijn van Steenbergen

minh thu wrote:

Also, I'd like to know why

id id True

is permitted but not

(\f -> f f True) id


Because this requires rank-2 types:


Prelude> :set -XScopedTypeVariables
Prelude> :set -XRank2Types
Prelude> (\(f :: forall a. a -> a) -> f f True) id
True


HTH,

Martijn.

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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: usb-0.1

2009-10-01 Thread Martijn van Steenbergen

Roel van Dijk wrote:

Yes, that happens. I don't now the cause but the work-around is easy.
Simply download the package manually from hackage, unpack and install
using cabal.

At least the following packages suffer from this problem:
  bindings-common
  bindings-libusb
  bindings-posix

Perhaps Maurí­cio can shed some light on this.


That's odd, even cabal unpack fails. Smells like a cabal bug. :-) I'll 
see if I can find if it's been reported before.


Martijn.

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


[Haskell-cafe] Re: [Haskell] ANNOUNCE: usb-0.1

2009-10-01 Thread Martijn van Steenbergen

Bas van Dijk wrote:

Comments and patches are highly welcome.


I tried to install on my Mac but bindings-common choked on:

> cabal install bindings-common
Resolving dependencies...
cabal: Error: some packages failed to install:
bindings-common-1.1 failed while unpacking the package. The exception was:
/var/folders/mR/mRFqQvztFo0URT0d6GN9wE+++TI/-Tmp-/bindings-common-1.174967/bindings-common-1.1/src/Bindings:
createDirectory: does not exist (No such file or directory)

Not sure if this is interesting to you, Bas, but I thought I'd share. :-)

Groetjes,

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


Re: [Haskell-cafe] A proposals

2009-09-28 Thread Martijn van Steenbergen

Bulat Ziganshin wrote:

in case you not seen this and may be interested:
http://okmij.org/ftp/Haskell/types.html#partial-sigs


Yes, I know there are workarounds (and I use them sometimes). It'd be 
nice if there was direct support for them. :-)


Thanks,

Martijn.

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


Re: [Haskell-cafe] A proposals

2009-09-28 Thread Martijn van Steenbergen

wren ng thornton wrote:
Another nice 
thing this suggests is the ability to use underscore as a pattern for 
when you know the compiler will infer the type but it's too complex to 
want to write out (e.g. while experimenting).


I'd love this!

M.

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


Re: [Haskell-cafe] Re: [Hs-Generics] how to automatically create and install documentations of a package?

2009-09-21 Thread Martijn van Steenbergen

Hi Michael,

Michael Shulman wrote:

Is there a way to make it automatically update a single contents page
with links to the documentation of all installed packages?


See:
  http://thread.gmane.org/gmane.comp.lang.haskell.cafe/53531/focus=53560
  http://thread.gmane.org/gmane.comp.lang.haskell.cafe/53531/focus=53572

HTH,

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


Re: [Haskell-cafe] Building a monoid, continuation-passing style

2009-09-16 Thread Martijn van Steenbergen

David Menendez wrote:

I'm reminded of the parameterized monad of continuations that Oleg
mentioned a few years back.




This is all very interesting, thank you both for the pointers!

I was trying to get rid of the newtypes but couldn't think of how to do 
that. I can't believe the solution now is as simple as (m -> r) -> a. 
There's hardly any code left, now.


The fact that it all exists already is nice on the one hand and sad on 
the other. :-)


I will have to look into parametrized monads and parametrized applicatives.

Thanks again,

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


[Haskell-cafe] Building a monoid, continuation-passing style

2009-09-14 Thread Martijn van Steenbergen

Hello cafe,

Inspired by Sean Leather's xformat package [1] I built a datatype with 
which you can build a monoid with holes, yielding a function type to 
fill in these holes, continuation-passing style. Here are some 
primitives and their types:



now   :: m -> ContSt m r r
later :: (a -> m) -> ContSt m r (a -> r)
run   :: ContSt m m r -> r
instance Monoid m => Category (ContSt m)


Here's an example of how to use it:


run (now "hello" . now "world")

"helloworld"


run (later id . now "world") "hello"

"helloworld"


run (later id . later show) "hello" 567

"hello567"

The source code is available at [2].

I have a couple of questions:
* ContSt is a Category. Is it also an Arrow? Why (not)?
* Did I miss any other obvious classes this type is an instance of?
* What is its relation with the Cont and Reader monads?
* Are there any other useful applications other than printf-like 
functionality?

* ContSt is a horrible name. What is a better one?

For those who have a bit more time: I appreciate any comments and 
suggestions on the code. :-)


Many thanks in advance,

Martijn.


[1] http://hackage.haskell.org/package/xformat
[2] http://code.google.com/p/monoid-cont/source/browse/trunk/ContSt.hs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] better error message for "undefined"

2009-09-10 Thread Martijn van Steenbergen
You can use the error function. It accepts a string that is displayed 
when the error is evaluated:



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.
Prelude> error "hi!"
*** Exception: hi!


HTH,

Martijn.


Andrew U. Frank wrote:
is there a way to have different kinds of undefined? such that i get a message 
which one was hit. something like writing in the code 'unefined 'my error 123' 
which prints 'undefined - my error 123' when it is accidentally hit.


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


Re: [Haskell-cafe] hmatrix on os x

2009-09-09 Thread Martijn van Steenbergen

brian wrote:

yep I had some trouble too, although interestingly less than on linux pc.

can you provide some error messages and we can see if your problems are 
the same one's I saw.


If this helps, here is the error message I got:

Configuring hmatrix-0.5.2.2...
Checking foreign libraries... FAIL
 *** Sorry, I can't link GSL.
 *** Please make sure that the appropriate -dev packages are installed.
 *** You can also specify the required libraries using
 *** cabal install hmatrix --configure-option=link:lib1,lib2,lib3,etc.
setup: Package hmatrix-0.5.2.2 can't be built on this system.
cabal: Error: some packages failed to install:
hmatrix-0.5.2.2 failed during the building phase. The exception was:
exit: ExitFailure 1

M.

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


Re: [Haskell-cafe] Is this Parsec code idiomatic?

2009-09-04 Thread Martijn van Steenbergen

Hi Serge,

Serge LE HUITOUZE wrote:

I'm asking some advice on a small piece of code representing a
simplified version of a treatment I need to perform.
I have a line-oriented string/file, from which I want to extract
only a substring of those lines starting with char '+' (the detail
of the extraction is irrelevant here, I'll just return what follows
the '+').


This isn't really answering your question, but I thought I'd share 
anyway: why use Parsec to retrieve those lines? It seems a simple 
function is a lot easier:


selectPlus :: String -> [String]
selectPlus = map tail . filter ((== '+') . head) . lines

I hope this helps you.

Martijn.

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


Re: [Haskell-cafe] ANNOUNCE: lenses -- Simple Functional Lenses

2009-09-03 Thread Martijn van Steenbergen

Job Vranish wrote:
A simple but powerful implementation of function lenses (aka functional 
references, accessors, etc..).


Nice! I will definitely give it a whirl when I pick up my MUD again. I'm 
currently using accessors there. I see your functions are limited to use 
in the state monad--you're right, I've never used accessors outside of a 
state monad yet.


I'm somewhat sad that you didn't capture lenses in a datatype, because 
it is such a nice example of a Category instance. I would like to see 
how to compose lenses to access deeper fields--I use nested data 
structures and would like to modify fields that are hidden deeper in the 
state. Can you perhaps add an example to show that?


Thanks!

Martijn.

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


Re: [Haskell-cafe] Can't get my head round monad transformers

2009-09-02 Thread Martijn van Steenbergen

Hi Colin,

Colin Adams wrote:

I'm trying to add a state monad onto the IO monad for use in a
happstack application. I thought this should involve using StateT and
Happstack.Server.SimpleHTTP.simpleHTTP', but I can't figure out how to
plumb it all together. Any tips will be welcome.


I'm not familiar with Happstack, but looking at the documentation:


simpleHTTP' :: (Monad m, ToMessage b) =>
  (m  (Maybe (Either Response a, FilterFun Response)) ->
   IO (Maybe (Either Response b, FilterFun Response))) ->
  Conf ->
  ServerPartT m a ->
  IO ()


Do I understand correctly you will be working with a

myAction :: ServerPartT (StateT S IO) A

?

Then it seems that you may call simpleHTTP' like this:

simpleHTTP'
  (\action -> evalStateT action initState)
  myConf
  myAction


The first argument (the lambda) has type

forall a m. Monad m => StateT S m a -> m a

which can be specialised to what simpleHTTP' is expecting.

I hope this helps!

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


Re: [Haskell-cafe] ANN: moe html combinator

2009-08-30 Thread Martijn van Steenbergen

Jason Dusek wrote:

  Say we have a nice thread on this and we all realize that the
  precedence of `do` and `case` could be changed (and changing
  `if` would be nice but we can't have everything). How many
  months/years would it take for any change in that direction to
  occur?


Seven!


(Sorry, working on theses on Sunday evenings makes for silly moods.)

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


Re: [Haskell-cafe] Mapping over multiple values of a list at once?

2009-08-27 Thread Martijn van Steenbergen

Right. How about:

f = map ((`div` 3) . sum . take 3) . tails

You probably want to do filter out some of the tails. Not sure where 
transpose comes into play, but tails is your friend here.


Martijn.


Miguel Mitrofanov wrote:

transpose & tails, I guess.


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


Re: [Haskell-cafe] Applicative and Monad transformers

2009-08-26 Thread Martijn van Steenbergen

Jeremy Shaw wrote:

What I would prefer is:

instance (Monad f, Applicative f) => Applicative (ReaderT r f) where
pure a = ReaderT $ const (pure a)
f <*> a = ReaderT $ \r -> 
  ((runReaderT f r) <*> (runReaderT a r))


Right. This doesn't only go for ReaderT, it already goes for Either, 
too: you don't want the 'ap' implementation for <*> there either.


These are beautiful examples of how applicative style gives the caller 
less power, but the callee more information, allowing more information 
to be retained. In this case it allows you to concatenate errors using 
mappend.


Another example is parsing: I believe Doaitse's parsers allow more 
optimization if they are only used in applicative style (but I'm not 
sure of this).


This shows there can be several sensible implementations of a type 
class. You ask which instance is right--that depends entirely on what 
you want it to do! Setting (<*>) = ap is just one of them, one you 
happen to get for free if your functor is already a monad.


Hope this helps,

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


Re: [Haskell-cafe] How to convert a list to a vector encoding its length in its type?

2009-08-25 Thread Martijn van Steenbergen

David Menendez wrote:

data SomeNat where SomeNat :: (Nat n) => n -> SomeNat
toPeano :: Int -> SomeNat

or, equivalently, by using a higher-order function.

toPeano :: Int -> (forall n. Nat n => n -> t) -> t


Nice! I thought the only way to create them was with a new datatype,
but this works too. I guess the nontrivial bit to think of is the 
introduction of a fresh type (t in this case). Thanks for this insight!


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


Re: [Haskell-cafe] Re: Parsec lookahead and <|>

2009-08-21 Thread Martijn van Steenbergen

Thanks for your replies.

Job Vranish wrote:

Martijn, how did you encounter this problem?


My list of input symbols contains some extra information and I was using 
lookahead to query for that information before doing the actual parsing. 
I was using it in various places, including a list of choices separated 
by <|>. I was assuming it wouldn't affect the choice but it turned out 
that Parsec was always going for the first one because I used a 
lookahead (see la) that always succeeds.


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


[Haskell-cafe] Parsec lookahead and <|>

2009-08-20 Thread Martijn van Steenbergen

Goedemiddag café,

Consider the following function, using parsec-3.0.0:


la :: Parsec String () (Maybe Char)
la = lookAhead (optionMaybe anyChar)


*Lookahead> parseTest (char 'a' <|> char 'b') "a"
'a'
*Lookahead> parseTest (char 'a' <|> char 'b') "b"
'b'
*Lookahead> parseTest (la *> char 'a' <|> char 'b') "a"
'a'
*Lookahead> parseTest (la *> char 'a' <|> char 'b') "b"
parse error at (line 1, column 2):
unexpected "b"
expecting "a"

The first three work fine and as expected, but the fourth example fails 
where I would expect success. I know <|> won't try the rhs if the lhs 
consumed input, but lookAhead's documentation promises not to consume 
any input. Is this a bug in Parsec or am I missing something?


Thanks,

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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: GLUT 2.2.1.0

2009-08-17 Thread Martijn van Steenbergen

Sven Panne wrote:
and simply pass the unknown button numbers via this case. I am not so sure 
about a nice name for this constructor: AdditionalButton? GenericButton? Or 
simply MouseButton, just like the type itself?


How about OtherButton?

Martijn.

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


Re: [Haskell-cafe] Monoid wants a (++) equivalent

2009-07-01 Thread Martijn van Steenbergen

Thomas Schilling wrote:

Haddock should allow documentation on instance
declarations...


+1!

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


Re: [Haskell-cafe] Monoid wants a (++) equivalent

2009-07-01 Thread Martijn van Steenbergen

Ross Paterson wrote:

Generalizing (++) will break some Haskell 98 code, e.g.

  append = (++)

I think that's a show-stopper.


Is the monomorphism restriction the only situation in which stuff breaks?

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


Re: [Haskell-cafe] Monoid wants a (++) equivalent

2009-07-01 Thread Martijn van Steenbergen

I suggest you all add your name and vote here:

   http://doodle.com/4yrfd7qaw5man3rm

Perhaps we'll find one of the options is clearly in favor.

Martijn.


Bryan O'Sullivan wrote:
I've thought for a while that it would be very nice indeed if the Monoid 
class had a more concise operator for infix appending than "a `mappend` 
b". I wonder if other people are of a similar opinion, and if so, 
whether this is worth submitting a libraries@ proposal over.





___
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] coding standard question

2009-06-29 Thread Martijn van Steenbergen

Jochem Berndsen wrote:

My default is to start developing, then adding -Wall -Werror and make it
compile again.


That and hlint!

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


Re: [Haskell-cafe] List spine traversal

2009-06-29 Thread Martijn van Steenbergen

Tony Morris wrote:

Is there a canonical function for traversing the spine of a list?

I could use e.g. (seq . length) but this feels dirty, so I have foldl'
(const . const $ ()) () which still doesn't feel right. What's the
typical means of doing this?


(seq . length) doesn't sound that bad to me.

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


Re: [Haskell-cafe] What is an "expected type" ...

2009-06-28 Thread Martijn van Steenbergen

Hi Michael,

michael rice wrote:

as opposed to an "inferred type"?


Can you deduce from the following example?


Prelude> let foo = () :: Int
:1:10:
Couldn't match expected type `Int' against inferred type `()'
In the expression: () :: Int
In the definition of `foo': foo = () :: Int



Hope this helps!

Martijn.

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


Re: [Haskell-cafe] combining monads with IO

2009-06-25 Thread Martijn van Steenbergen

Richard Silverman wrote:
I'm puzzled by something. Suppose I have some code that does lots of IO, 
and also occasionally refers to some global state. No problem, use 
ReaderT for the state, combining with the IO monad. Except... since IO 
is on the bottom, simple uses of do-notation such as "foo <- ask" work 
in the Reader monad, and to access the IO monad, I need to lift, e.g. 
(bar <- liftIO getLine). If my code does lots of IO, this is *very* ugly 
-- the code is littered with lift functions!  Is there no cleaner way to 
do this?


Not that I know of. However, you can usually group IO-statements 
together in one bigger block:


blah = do
  foo <- ask
  biz <- liftIO $ do
meep
bop foo
bleep foo
  zap biz

etc.

And if there is a limited number of specific functions you need to lift 
often, you can write generalised MonadIO-based versions of these so that 
you can call them directly from the monad transformer:


  getLine :: MonadIO m => m String
  getLine = liftIO SystemIO.getLine

Assuming an appropriate MonadIO instance of ReaderT, of course.

Does that help?

Martijn.

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


Re: [Haskell-cafe] Weird thing happened when I use gtk2hs with concurrent.

2009-06-24 Thread Martijn van Steenbergen

Magicloud Magiclouds wrote:

61   threadDelay 1 -- ten seconds, but it just refresh crazy!


That's because threadDelay expects microseconds, not milliseconds. Try 
multiplying your delay by 1000.


HTH,

Martijn.

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


  1   2   3   >