Re: [Haskell-cafe] COM and Haskell

2007-04-30 Thread Simon Marlow

Andrew Appleyard wrote:

On 26/04/2007, at 12:12 am, Bulat Ziganshin wrote:


Simon Marlow recently wrote paper about handling dynamic exceptions -
for me it seems that he described general system to mimic OOP in Haskell


I found the paper (titled 'An Extensible Dynamically-Typed Hierarchy of 
Exceptions').  The system described is not a complete OO mapping (it 
doesn't deal with method overloading, for example) however because it is 
a recent paper and the mapping is quite lightweight it could be useful 
to me.


The best reference I know of for how to do OO in Haskell is the Kiselyov/Lämmel 
OOHaskell paper: http://homepages.cwi.nl/~ralf/OOHaskell/.  Quite often you 
don't need the full range of OO functionality to implement a particular 
abstraction, and in that case you can pick from the menu of techniques described 
in that paper.  Extensible exceptions is one particular example of an OO-like 
abstraction.


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


Re: [Haskell-cafe] Poor first impression

2007-04-30 Thread ls-haskell-developer-2006

 5) The gigantic README with it's obscure note is here
 http://www.haskell.org/ghc/download_ghc_661.html a few lines away from
 the download link.  You can probably read it in the time it takes you
 to find and click the download link.  Much quicker than waiting for a
 configure script to detect the problem.

Also, just in case one doesn't know where to look, doing a web search
for 'ghc libreadline.so.4' gives enough hits to solve the
problem. The OP insisisted on compiling from the source (which is OK),
instead of using the distributions package (which would have been
worked). In this case I expect enough know how to understand what the
error message means and being able to install libreadline4. If one
hasn't got the know how I expect that one asks nicely (what can I do
/ what does that mean) instead of just venting one's frustration in a
rather destructive manner (you bloody program didn't work for me, so
I won't use it ever again, there!).

Regards -- Markus

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


[Haskell-cafe] ANN: The Monad.Reader - Issue7

2007-04-30 Thread Wouter Swierstra


I am pleased to announce that the latest issue of The Monad.Reader is  
now available:


http://www.haskell.org/haskellwiki/The_Monad.Reader

Issue 7 consists of the following four articles:

* Matthew Naylor
A Recipe for controlling Lego using Lava

* Yaron Minsky
Caml Trading: Experiences in Functional Programming on Wall Street

* Duncan Coutts
Book Review: “Programming in Haskell” by Graham Hutton

* Dimitry Golubovsky, Neil Mitchell, Matthew Naylor
Yhc.Core – from Haskell to Core

The Monad.Reader is a quarterly magazine about functional  
programming. It is less-formal than journal, but somehow more  
enduring than a wiki page or blog post.


If you'd like to submit something to the next issue of The  
Monad.Reader, please get in touch. I haven't fixed the deadline for  
the next issue just yet; I hope to send out an official call for copy  
in the coming weeks.


  Wouter
This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


[Haskell-cafe] Re: [Haskell] Re: Newbie: what are the advantages of Haskell?

2007-04-30 Thread Rafael

I'll study these ways to debugging Haskell, and in accordance with my final
work plan I'll decide the better way to follow.. For the moment i'm studing
Haskell things, but in the next times I'll might decide it.

A lot of thanks Neil and Simon.


On 4/30/07, Simon Marlow [EMAIL PROTECTED] wrote:

Rafael wrote:
 Hi

 HTTP. We also need better availability of libraries, and a more
 standard and reliable way to install them and specify their
 dependencies. We could also do with a good debugger. These are being
 addressed by the Google Summer of Code project.

 Hi Neil, a good debugger ? What is in Google Summer of Code about it ?

 I just found it:
 http://hackage.haskell.org/trac/summer-of-code/ticket/6
 that havent student related.

 I was studing about debuging techs for haskell to build a nice
 debugging enviorment in HIDE or some other IDE. It's my bacharelor
 final work.

We're building some debugging features into GHCi.  This started with Pepe
Iborra's Summer of Code project last year, and more recently Bernie Pope
reworked the breakpoint support during his internship here at MSR

Cambridge.  We

are actively working on polishing what we have for inclusion in the next

major

GHC release.

The GHCi debugger is based on imperative debugging techniques:

breakpoints,

single stepping, etc.  It's a live debugger rather than post-mortem.  We
focussed on accessibilty, rather than functionality: so the debugger is

always

on, and it works with everything that you can compile in GHCi.  It lacks

some of

the advanced debugging features you'll find in Hat, for example, but we

hope it

makes up for that by being more broadly accessible.

More information on the debugger is here:

  http://hackage.haskell.org/trac/ghc/wiki/NewGhciDebugger

although note that development is ongoing and more features have been

added

since the wiki was last updated.

All the debugging functionality is exposed by the GHC API, so it's

certainly

possible to build debugging support into an IDE based on GHC.

Cheers,
   Simon

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


[Haskell-cafe] Indexing of content at haskell.org by search engines

2007-04-30 Thread Henning Thielemann

I have noticed that only parts haskell.org are indexed by Google. E.g.
mail archives of Haskell-Cafe and HaskellWiki are not indexed, but
cvs.haskell.org, darcs.haskell.org and hackage.haskell.org are.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Poor first impression

2007-04-30 Thread Simon Marlow

[EMAIL PROTECTED] wrote:

5) The gigantic README with it's obscure note is here
http://www.haskell.org/ghc/download_ghc_661.html a few lines away from
the download link.  You can probably read it in the time it takes you
to find and click the download link.  Much quicker than waiting for a
configure script to detect the problem.


Also, just in case one doesn't know where to look, doing a web search
for 'ghc libreadline.so.4' gives enough hits to solve the
problem. The OP insisisted on compiling from the source (which is OK),


Just wanted to clear up a misconception I've seen several times in this thread: 
the OP was *not* building from source, he was installing from a binary 
distribution tarball.  The confusion no doubt arises because our binary tarball 
has a configure script and a Makefile.  The real build system *does* check for 
readline, as it should.


The tarball is built on an old RedHat 9 system with readline 4 on it.  The main 
reasons we supply the binary tarball (as opposed to distro packages) are so that 
you can install GHC in your home directory, or install multiple versions of GHC, 
or try out new releases without installing them system-wide.  I'm going to 
upgrade the machine that builds these distributions at some point, but it's in 
the data center and I find it a bit cold and windy in there :-)


Typically the best way to get GHC on Linux is directly from your distro.  The 
download page for 6.6.1 is currently not particularly helpful, we will be 
improving it in due course.


Cheers,
Simon

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


[Haskell-cafe] RE:Cross-over from Haskell.org [Haskell] Re: Newbie: what are the advantages of Haskell?

2007-04-30 Thread Taillefer, Troy (EXP)
Udo,

I am cross posted/migrated this to Haskell-cafe per Simons request

sorry for the late response I don't check this email on weekends

I really dislike Perl as a programming language but I have to strongly 
disagree about your statements about CPAN and the quality of its
contents.
I have worked professional in Perl (Feel free to feel sorry for me) for
over a year
and I have always been impressed with what I could find in CPAN.

Perl obviously has a niche and is well supported by its community. 

Perl is popular so it must have some merit. I don't subscribe to the
flawed reasoning that Perl Hackers just don't know any better or that
they are dumb, or intellectual inferior in some way. Programmers have
very good and valid reason for choosing their tools and I will have
words for those who irrational state otherwise especially in a
belittling manner I am pro choice.

I am going to borrow some Ebonics

Don't language Hate Appreciate

Troy

 


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Udo Stenzel
Sent: Saturday, April 28, 2007 7:06 AM
To: [EMAIL PROTECTED]
Subject: Re: [Haskell] Re: Newbie: what are the advantages of Haskell?

Michael T. Richter wrote:
 I wish I knew the language better so I could start working on those 
 libraries.

Which ones?  those libraries cannot come into existence until someone
says what's actually missing.  (The bulk of CPAN is crap and is
certainly not worth being reimplemented.)


-Udo
--
Object-oriented programming is an exceptionally bad idea which could
only have originated in California.  -- E. W. Dijkstra
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Getting the number of seconds since epoch from System.Time.ClockTime

2007-04-30 Thread Simon Marlow

Martin Percossi wrote:

Hello haskell-cafe,

In System.Time,

data ClockTime = TOD Integer Integer

, where the first integer represents the number of seconds since epoch, 
and the other represents the number of picoseconds. Is there a way of 
retrieving the first part? (In Haskell 98, the ClockTime type is abstract).


Better to use the new time package, in particular Data.Time.Clock.POSIX:

http://www.haskell.org/ghc/docs/latest/html/libraries/time/Data-Time-Clock-POSIX.html

getPOSIXTime will do what you want.

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


[Haskell-cafe] Bloom Filter

2007-04-30 Thread tom

Hi all,

I'm pretty new to Haskell, I've been working on a Bloom filter[1]
implementation as a learning exercise.

I'd really appreciate it if someone more experienced would comment on
the code. I'm sure there's plenty of places where I'm doing things in
silly or overly complex ways.

I've packaged it all with Cabal because I wanted to see how that all
worked, I don't think it's ready for release yet! I would like to at
some point get it polished up and release it if anyone thinks it might
be useful.

You can download it at:

http://www.almostobsolete.net/bloom-0.0.tar.gz

I've also put the Haddock docs for it online at:

http://www.almostobsolete.net/doc/html/Data-yBloom.html

All comments will be very much appreciated :p

Thanks

Tom

[1] There's a nice description of what a Bloom filter is here:
http://www.cs.wisc.edu/~cao/papers/summary-cache/node8.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Poor first impression

2007-04-30 Thread brad clawsie
  4) The fix to the bug is simply download and install the libreadline4 
  shared object.  No recompilation or reinstallation necessary.

i'm not sure if this has been addressed - but is there a specific
reason an older version of the readline library is in use? v5 appears
to be stable and has been in use for some time now.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Type-level programming problem

2007-04-30 Thread Thomas Schilling

Hi,

I have a type class similar to this one.

data T
class Foo ns a b c | ns - a, ns - b, ns - c where
mkFoo :: ns
defaultA :: a
defaultB :: c - IO b
defaultC :: [T] - c
f :: c - b - a - (b, Int)

The idea is, that I define classes of components where the data types  
of the methods are component-specific.  I therefore use a namespace  
to define the component types (associated types would be nicer, but  
are not widely supported).


Given a few sample instances, I can define a configuration:

data X;  data XA = XA;  data XB = XB;  data XC = XC

instance Foo X XA XB XC where
mkFoo = undefined
defaultA= XA
defaultB XC = return XB
defaultC _  = XC
f _ b _ = (b,0)
mkX = mkFoo :: X

data Y;  data YA = YA;  data YB = YB;  data YC = YC

instance Foo Y YA YB YC where
mkFoo = undefined
defaultA= YA
defaultB YC = return YB
defaultC _  = YC
f _ b _ = (b,1)
mkY = mkFoo :: Y


config = mkX .*. mkY .*. HNil

Using this configuration, I now want to define various functions that  
work on As, Bs or Cs, respectively.  For example, I'd like to have


a :: XA :*: XB :*: HNil
a = hMap DefaultA config

but I fail to figure out how to define DefaultA.  I tried with this one:

data DefaultA
instance Foo ns a b c = Apply DefaultA ns a where
apply _ _ = defaultA

but I get:

Could not deduce (Foo ns1 a b1 c1)
  from the context (Apply MakeAs ns a, Foo ns a b c)
  arising from use of `defaultA'
  at /Users/nominolo/Devel/Haskell/testcase1.hs:126:16-23
Possible fix:
  add (Foo ns1 a b1 c1) to the class or instance method `apply'
In the expression: defaultA
In the definition of `apply': apply _ _ = defaultA
In the definition for method `apply'

I guess I need some type class that also binds b and c.  Or maybe I  
need to do some things completely different at all.  Ideally, I'd  
hope to keep the work for adding new Foo instances as low as  
possible, though.


I attached the relevant parts of the HList implementation and the code.

Any suggestions?

/Thomas



testcase1.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] FIT for Haskell

2007-04-30 Thread Philipp Volgger
Who wrote FIT for Haskell on http://darcs.haskell.org/FIT/? Does anybody 
know if the version is stable?

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


Re: [Haskell-cafe] Poor first impression

2007-04-30 Thread ls-haskell-developer-2006

brad clawsie [EMAIL PROTECTED] writes:

  4) The fix to the bug is simply download and install the libreadline4 
  shared object.  No recompilation or reinstallation necessary.

 i'm not sure if this has been addressed - but is there a specific
 reason an older version of the readline library is in use? v5 appears
 to be stable and has been in use for some time now.

Actually some sources recommend to just symlink libreadline.so.4 to
libreadline.so.5. I haven't tried, but since version 5 is supposed to
be upwards compatible to version 4 it's reasonable to expect that it
works (to a certain extend).

To me (as an outsider) the whole thing certainly looks like a
quirk/buglet in the ghc build process (why not just link to the
available readline?), but IMO that is no reason for a ghc is not ripe
for prime time outcry. Ghc is for programmers and there is a certain
extend of ability to help yourself I'd be expecting from
programmers. If one doesn't have it, he/she should just use the
packages of his/her distro or another distro.

Regards -- Markus


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


Re: [Haskell-cafe] Poor first impression

2007-04-30 Thread brad clawsie
On Mon, Apr 30, 2007 at 08:26:35PM +0200, [EMAIL PROTECTED] wrote:
 
 Actually some sources recommend to just symlink libreadline.so.4 to
 libreadline.so.5. I haven't tried, but since version 5 is supposed to
 be upwards compatible to version 4 it's reasonable to expect that it
 works (to a certain extend).

there is an even simpler solution, upgrade the linux version on the
build box. from a previous email by simon marlow:

The tarball is built on an old RedHat 9 system with readline 4 on it

rh9 is over four years old, and those four years there have been
countless upgrades in many key free software packages used by linux distros.

installing a modern linux on this box is a thirty minute exercise.

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


Re: [Haskell-cafe] Poor first impression

2007-04-30 Thread Andrew Coppin

brad clawsie wrote:

installing a modern linux on this box is a thirty minute exercise.
  

Ah - a volunteer! :-)

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


[Haskell-cafe] 'Proper' use of the State monad

2007-04-30 Thread Denis Volk

Hello all,

I am trying to make a (turn-based) game in Haskell and need to pass
around quite a bit of information, so using the State monad seems most
appropriate. My question is, which is a better idea:

1) Using State GameState r and then call execState for each game event
(i.e. user input) so I can do IO
2) Using StateT GameState IO () and have the entire game live in one
big execStateT call. (I note XMonad does something similar.)

There are difficulties with the first option, including keeping even
more state about what we're doing (for instance, are we in a menu?),
and adding stuff later would possibly require substantial rewrites.
Other than the fact that I would have IO in places where it perhaps
shouldn't be, the second option seems better, but I am new to all this
and it may be that I'm missing something.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] 'Proper' use of the State monad

2007-04-30 Thread Sebastian Sylvan

On 4/30/07, Denis Volk [EMAIL PROTECTED] wrote:


Hello all,

I am trying to make a (turn-based) game in Haskell and need to pass
around quite a bit of information, so using the State monad seems most
appropriate. My question is, which is a better idea:

1) Using State GameState r and then call execState for each game event
(i.e. user input) so I can do IO
2) Using StateT GameState IO () and have the entire game live in one
big execStateT call. (I note XMonad does something similar.)

There are difficulties with the first option, including keeping even
more state about what we're doing (for instance, are we in a menu?),
and adding stuff later would possibly require substantial rewrites.
Other than the fact that I would have IO in places where it perhaps
shouldn't be, the second option seems better, but I am new to all this
and it may be that I'm missing something.




I like the second option better too. Also, you can make this type opaque
(stick it in a newtype, use newtype deriving to derive the appropriate
classes) and only export whatever IO actions you want to support (e.g. you
may want to be able to spawn off a thread in a game for concurrent AI, so
you could wrap that in a function that can only fork off Game actions, and
not general IO actions, also you may want to be able to store certain game
properties to disk for e.g. save games, but not allow general disk writes,
so you only suply a savegame abstraction).
You still get a nice encapsulation of what kind of IO actions people can do,
because you don't have to allow them the use of lift or liftIO.




--
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] 'Proper' use of the State monad

2007-04-30 Thread Isaac Dupree
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Denis Volk wrote:
 There are difficulties with the first option, including keeping even
 more state about what we're doing (for instance, are we in a menu?),
 and adding stuff later would possibly require substantial rewrites.
 Other than the fact that I would have IO in places where it perhaps
 shouldn't be, the second option seems better, but I am new to all this
 and it may be that I'm missing something.

Are you going to be making lots of separate little sequenced changes to
the state?  If not, passing it around explicitly may be clearer.  It may
be helpful to distinguish between logical game state and the
user-interface parts (such as in a menu), possibly putting them in
different 'data', different parts of the code.


Hoping that was any help,

Isaac

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGNl9WHgcxvIWYTTURAr2LAJ9uGh09lTvfJ9wIRHmGszN5VQH2BwCfb2kQ
6GMUVZrggM3y1oZyk+UU49w=
=kJhf
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] 'Proper' use of the State monad

2007-04-30 Thread Stefan O'Rear
On Mon, Apr 30, 2007 at 11:16:47PM +0200, Denis Volk wrote:
 Hello all,
 
 I am trying to make a (turn-based) game in Haskell and need to pass
 around quite a bit of information, so using the State monad seems most
 appropriate. My question is, which is a better idea:
 
 1) Using State GameState r and then call execState for each game event
 (i.e. user input) so I can do IO
 2) Using StateT GameState IO () and have the entire game live in one
 big execStateT call. (I note XMonad does something similar.)
 
 There are difficulties with the first option, including keeping even
 more state about what we're doing (for instance, are we in a menu?),
 and adding stuff later would possibly require substantial rewrites.
 Other than the fact that I would have IO in places where it perhaps
 shouldn't be, the second option seems better, but I am new to all this
 and it may be that I'm missing something.

You can also give some of your actions the type Monad m = StateT
GameState m (), so that parametricity guarantees no actual IO will
occur. 

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


Re: [Haskell-cafe] Poor first impression

2007-04-30 Thread brad clawsie
On Mon, Apr 30, 2007 at 09:53:06PM +0100, Andrew Coppin wrote:
  brad clawsie wrote:
  installing a modern linux on this box is a thirty minute exercise.

  Ah - a volunteer! :-)

absolutely! for the low cost of one round-trip business-class seat from
san jose to wherever this box is, and i will happily insert a recent 
ubuntu cd and click the install icon.

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


Re: [Haskell-cafe] Re: Creating pseudo terminals

2007-04-30 Thread Tom Hawkins

On 4/29/07, Georg Sauthoff [EMAIL PROTECTED] wrote:

On 2007-04-29, Tom Hawkins [EMAIL PROTECTED] wrote:

Hi,

[..]
 I haven't done this before in any language, so any tips would be
 appreciated.  From what I gather, a call to posix_openpt or openpty
 returns a master and a slave, or alternatively opening /dev/ptmx
 followed by calls to grantpt and unlockpt.

well, then I suggest 'Stevens, Advanced programming in the unix
environment' for basic pseudo terminal programming.


Thanks for the reference.

Does Haskell's standard library support pseudo terminals, or will I
have to write foreign interfaces for grantpt and unlockpt?

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


Re: [Haskell-cafe] Re: Creating pseudo terminals

2007-04-30 Thread Donald Bruce Stewart
tomahawkins:
 On 4/29/07, Georg Sauthoff [EMAIL PROTECTED] wrote:
 On 2007-04-29, Tom Hawkins [EMAIL PROTECTED] wrote:
 
 Hi,
 
 [..]
  I haven't done this before in any language, so any tips would be
  appreciated.  From what I gather, a call to posix_openpt or openpty
  returns a master and a slave, or alternatively opening /dev/ptmx
  followed by calls to grantpt and unlockpt.
 
 well, then I suggest 'Stevens, Advanced programming in the unix
 environment' for basic pseudo terminal programming.
 
 Thanks for the reference.
 
 Does Haskell's standard library support pseudo terminals, or will I
 have to write foreign interfaces for grantpt and unlockpt?

I'm not aware of an existing binding, so I'd suggesting writing your
own. Should be pretty simple.

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


[Haskell-cafe] Bay Area Haskell users' group, anyone?

2007-04-30 Thread Tim Chevalier

Hello all,
With all the user groups that seem to have been forming lately, I
figure it's high time to start a Bay Area group for people interested
in Haskell (on any level). I interpret Bay Area broadly, since I'm
in Monterey -- perhaps encompassing all of Northern California. If
you're potentially interested, reply to me off-list, and I'll see what
kind of response I get. I imagine that the first meeting, at least,
would consist of people gathering informally over food, drink, or
such.

Cheers,
Tim

--
Tim Chevalier * [EMAIL PROTECTED] * Often in error, never in doubt
Confused? See http://catamorphism.org/transition.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Bloom Filter

2007-04-30 Thread ajb
G'day.

Quoting tom [EMAIL PROTECTED]:

 I'm pretty new to Haskell, I've been working on a Bloom filter[1]
 implementation as a learning exercise.

Excellent!  Sounds like a fun test.

 I'd really appreciate it if someone more experienced would comment on
 the code. I'm sure there's plenty of places where I'm doing things in
 silly or overly complex ways.

Sure.

All in all, very well done.  It works, and it looks pretty efficient.
My quibbles are mostly stylistic or syntactic in nature.  Please
understand that the relative triviality of my quibbles is a sign that
there are really no major problems.

This is not a criticism, but more an advertisement: What are you using
for source control here?  Darcs is nice, and as a bonus, it's trivially
browsable from a web browser, which saves downloading and unpacking.

General comments:

You overuse parentheses.  A lot.  Definitions like this:

ary = (listArray (0, wordc-1) (repeat 0))

don't need parentheses around them, and just add to the general noise
level.

And (.. ((size b)-1)) is much more cleanly expressed as (.. (size b - 1)).

Rather than carrying around a hash function, it might be better to use
a type class:

class BloomHash k where
bloomHash :: k - [Word8]

In wordsize:

You don't need to hard-code this.  You can use:

wordsize = bitSize (undefined::Word32)  -- Or Int, of course!

bitSize is defined in Data.Bits.

In splitup:

I got a bit confused by the local binding names.  It's usual, especially
in generic code, to use xs, ys etc for a list of x and y.
Something like this might be more idiomatic:

splitup n xs = let (xs1, xs2) = splitAt n xs
   in xs1 : splitup n xs2

In indexes:

(fromIntegral $ x `div` wordsize, fromIntegral $ x .. (wordsize-1))

Seems intuitively wasteful.  Either use divMod or bit operations.

Similarly, (hashfunc b) key is the same as hashfunc b key.  But even
better is:

split bytecount . hashfunc b $ key

That makes it obvious that it's a pipeline of functions applied to the key.

This looks cool:

bytes2int = foldr ((. (256 *)) . (+)) 0 . (map toInteger)

but I'm not smart enough to parse it.  This is both more readable and
shorter:

bytes2int = foldr (\x r - r*256 + fromInteger x) 0

Integer log2's are probably better done using integers only, or at least
abstracted out into a separate function.

In bloom:

Function guards are your friends!  This:

bloom hf sz hc = if condition
 then b
 else error Badness

is almost always better expressed as:

bloom hf sz hc
  | condition = b
  | otherwise = error Badness

You can now inline b.  (I can see why you put it in a where clause; now
you don't have to.)

wordc, again, only needs integral arithmetic:

wordc = ceiling ((fromIntegral a) / (fromIntegral b :: Double))

is more or less:

wordc = (a+b-1) `div` b

And drop the parentheses around the definition of ary.

In add:

Try to use function names that are close to names in existing libraries,
like Data.Set.  insert sounds better here.

Also, rather than this:

add :: Bloom a - a - Bloom a

a better argument order is this:

insert :: a - Bloom a - Bloom a

That way, you can use it with foldr.

In test:

Again, probably misnamed.  Data.Set calls this member.  And again,
arguably the wrong argument ordering.

Once again, well done.

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


Re: [Haskell-cafe] Bloom Filter

2007-04-30 Thread Donald Bruce Stewart
ajb:
 Quoting tom [EMAIL PROTECTED]:
 This looks cool:
 
 bytes2int = foldr ((. (256 *)) . (+)) 0 . (map toInteger)
 
 but I'm not smart enough to parse it.  This is both more readable and
 shorter:
 
 bytes2int = foldr (\x r - r*256 + fromInteger x) 0
 
 Integer log2's are probably better done using integers only, or at least
 abstracted out into a separate function.

Reminds me of this code from Data.Binary:

unroll :: Integer - [Word8]
unroll = unfoldr step
  where
step 0 = Nothing
step i = Just (fromIntegral i, i `shiftR` 8)

roll :: [Word8] - Integer
roll   = foldr unstep 0
  where
unstep b a = a `shiftL` 8 .|. fromIntegral b

Which is a bit stream-fusion inspired, I must admit.

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


Re: [Haskell-cafe] Poor first impression

2007-04-30 Thread Michael T. Richter
On Mon, 2007-30-04 at 18:35 -0700, brad clawsie wrote:

 On Mon, Apr 30, 2007 at 09:53:06PM +0100, Andrew Coppin wrote:
   brad clawsie wrote:
   installing a modern linux on this box is a thirty minute exercise.
 
   Ah - a volunteer! :-)
 
 absolutely! for the low cost of one round-trip business-class seat from
 san jose to wherever this box is, and i will happily insert a recent 
 ubuntu cd and click the install icon.


You beat me to it.

-- 
Michael T. Richter [EMAIL PROTECTED] (GoogleTalk:
[EMAIL PROTECTED])
The most exciting phrase to hear in science - the one that heralds new
discoveries - is not Eureka! but That's funny... (Isaac Asimov)


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


[Haskell-cafe] Type-level programming problem

2007-04-30 Thread oleg

Thomas Schilling wrote:
 data T
 class Foo ns a b c | ns - a, ns - b, ns - c where
  mkFoo :: ns
  defaultA :: a
  defaultB :: c - IO b
  defaultC :: [T] - c
  f :: c - b - a - (b, Int)

 data DefaultA
 instance Foo ns a b c = Apply DefaultA ns a where
  apply _ _ = defaultA

 but I get:

  Could not deduce (Foo ns1 a b1 c1)
from the context (Apply MakeAs ns a, Foo ns a b c)
arising from use of `defaultA'

Indeed. Let us examine the inferred type of defaultA:
*Main :t defaultA
defaultA :: (Foo ns a b c) = a

We see it is a value polymorphic over four type variables: ns, a, b,
and c. The type variable 'a' is also the type of the value, so we have
a way to instantiate it. There is no direct way to instantiate the
remaining three. If there were a functional dependency a - ns, a-b,
a-c, we could have instantiated the remaining variables. But there
are no such dependencies. So, there is really no way we can
ever instantiate the type variables ns, b and c -- and so the typechecker
will complain.

So, we need either a functional dependency a - ns in the definition
of Foo, or defaultA should have a signature defaultA :: ns - a
(and ditto for other defaults). As I understand, the function
'defaultA' can be present in different components, identified by
ns. When we write 'defaultA' however, how can we say that we mean
defaultA of component X rather than of component Y? There isn't any
way to name the desired component...

Incidentally, if we represent components by records
data XRec = XRec { defaultA :: XA }
then the type of defaultA is Xref - XA. It is the function from the
type of the `namespace'. This seems to suggest the
signature of defaultA should be ns - a ...

BTW, there are other ways to add the name of the namespace to the
signature of defaultA. For example:
newtype TaggedT ns a = TaggedT a
class Foo ns a b c | ... 
 defaultA :: TaggedT ns a
or
class Foo ns a b c | ... 
 defaultA :: ns a

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