Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Galchin, Vasili
ok ... by using newtype, we are constricting/constraining to a subset of
CInt .. e.g. something like a subtype of CInt?? (where by subtype, I
mean like the notion of subtype in languages like Ada). For our audience,
can you perhaps distinguish (in a typeful way) between the Haskell notion of
type, newtype and data? Or maybe let's distinguish between these
notions not only in a typeful manner, but also in a historical motivation?
.. ...  motivations are always IMO very, very enlightening!


Regards, vasili

On Mon, Oct 6, 2008 at 12:47 AM, Don Stewart [EMAIL PROTECTED] wrote:

 Used wisely, newtype prevents accidentally constructing illegal values
 of Signal type, by treating them as CInts. You can restrict the valid
 values of the Signal type to be just those signals you define, not
 arbitrary bit patterns that fit in a CInt.

 vigalchin:
 Thanks Don. Maybe both for me and others in order to take the fight to
 the
 Klingons and other Baddies, please explain the typefulness
 protection
 that newtype affords over the Klingon  type ...  In the code
 that I
 contributed to the library, I like to think that I used newtype
 appropriately but not perhaps with full understanding.
 
 Thanks, Vasili
 
 On Mon, Oct 6, 2008 at 12:37 AM, Don Stewart [EMAIL PROTECTED]
 wrote:
 
   vigalchin:
   Hello,
   
  I am reading some extant Haskell code that uses Posix
   signals I am
   confused by the motivation of the following ...
   
   type [1]Signal = [2]CInt
   [3]nullSignal :: [4]Signal
   [5]internalAbort :: [6]Signal
   [7]sigABRT :: [8]CInt
   [9]realTimeAlarm :: [10]Signal
   [11]sigALRM :: [12]CInt
   [13]busError :: [14]Signal
   [15]sigBUS :: [16]CInt
   
   OK .. type is really just a synomym and doesn't invoke type
   checking
   like data type declarations do .. so why don't we have all
 the
   CInts
   substituted by Signal? I.e. what did I miss?
 
   Looks like it should all be Signal, and probably should be using a
   newtype, to prevent funky tricks. The Posix layer is a bit crufty.
   -- Don
 
  References
 
 Visible links
 1. mailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Johan Tibell
2008/10/6 Galchin, Vasili [EMAIL PROTECTED]:
 ok ... by using newtype, we are constricting/constraining to a subset of
 CInt .. e.g. something like a subtype of CInt?? (where by subtype, I
 mean like the notion of subtype in languages like Ada). For our audience,
 can you perhaps distinguish (in a typeful way) between the Haskell notion of
 type, newtype and data? Or maybe let's distinguish between these
 notions not only in a typeful manner, but also in a historical motivation?
 .. ...  motivations are always IMO very, very enlightening!

Here's an example of using newtypes:

module Main where

newtype Flag = Flag Int

-- These are the only legal values:
flag1 :: Flag
flag1 = Flag 1

flag2 :: Flag
flag2 = Flag 2

fun :: Int - Flag - Int
fun n (Flag f) = undefined  -- Implementation goes here.

-- Using `fun`.

main = do
  print (fun 10 flag1)
  -- Oh noes, the programmer messed up and reordered the
  -- arguments!
  print (fun flag1 10)

Saved by the type checker:

/home/tibell/Test.hs:21:13:
Couldn't match expected type `Int' against inferred type `Flag'
In the first argument of `fun', namely `flag1'
In the first argument of `print', namely `(fun flag1 10)'
In the expression: print (fun flag1 10)
Failed, modules loaded: none.

By creating a module that doesn't export the constructor used to
create e.g. `Flag` and only the constants `flag1` and `flag2` we can
make sure that no one ever calls `fun` with an illegal value.

I hope this helps.

Cheers,

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


Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Jason Dagit
2008/10/5 Galchin, Vasili [EMAIL PROTECTED]

 ok ... by using newtype, we are constricting/constraining to a subset of
 CInt .. e.g. something like a subtype of CInt?? (where by subtype, I
 mean like the notion of subtype in languages like Ada). For our audience,
 can you perhaps distinguish (in a typeful way) between the Haskell notion of
 type, newtype and data? Or maybe let's distinguish between these
 notions not only in a typeful manner, but also in a historical motivation?
 .. ...  motivations are always IMO very, very enlightening!


If you like historical perspective check out this:
http://research.microsoft.com/~simonpj/papers/history-of-haskell/index.htm

type is similar to typedef in C.  That is, it's more or less just for
renaming.  I say more or less because I'm not sure exactly how the
renaming works in the presence of rank-2 and higher types.

data is essentially for declaring new data structures.  As a result of this
it also defines a new type.

newtype is for reusing existing types or data structures but with a new
distinct type.

data and newtype vary in one more subtle way, and that's how/when they
evaluate to bottom.  Most of the time they behave identically, but in the
right cases they act sightly differently.  newtype is usually regarded as
more efficient than data.  This is because the compiler can choose to
optimize away the newtype so that it only exists at type check time.  I
think this is also possible with data in some, but not all, uses.

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


Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Don Stewart
dagit:
data and newtype vary in one more subtle way, and that's how/when they
evaluate to bottom.  Most of the time they behave identically, but in the
right cases they act sightly differently.  newtype is usually regarded as
more efficient than data.  This is because the compiler can choose to
optimize away the newtype so that it only exists at type check time.  I
think this is also possible with data in some, but not all, uses.

The compiler *must* optimise away the use. They're sort of 'virtual'
data, guaranteed to have no runtime cost.

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


RE: [Haskell-cafe] Hoogle? [Stacking monads]

2008-10-06 Thread Mitchell, Neil
Hi

 Try doing a Hoogle search for c1 (c2 x) - c2 (c1 x). 
 Hoogle correctly states that Data.Traversable.sequence will 
 do it for you.
 
 Now try doing c1 k (c2 x) - c2 (c1 k x). The 'sequence' 
 function will also do this, but now Hoogle returns 0 results.
 
 This is puzzling, since AFAIK, the above two type signatures 
 are equvilent in some sense. (Specifically, replace every 
 type X with type Y and you get from one to the other.) To me, 
 this looks like a Hoogle bug. (It goes without saying that 
 Hoogle also failed to find anything for the more specific 
 type signature I was searching for, despite the fact that 
 'sequence' unifies with it.)

Hoogle is not a unification engine - since that is very rarely what
people want out of a type search engine. What it is is an approximate
matcher. Let's compare the two types:

Your search :: c1 k (c2 x) - c2 (c1 k x)

sequence :: Monad m = [m a] - m [a]

Are you expecting c1 (:: * - * - *) to unify with [] (:: * - *)? That
seems kind incorrect at the very last. Additionally, those types don't
look all that close.

But, let's briefly consider unification (and why Hoogle doesn't used
it). Consider the search:

Eq a = [(a,b)] - a - b

What the user wants is lookup, which sadly doesn't unify. However,
undefined unifies perfectly.

Thanks

Neil


==
Please access the attached hyperlink for an important electronic communications 
disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==

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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: SourceGraph-0.1 and Graphalyze-0.3

2008-10-06 Thread Magnus Therning
Ivan,

I tried building your tool today and found a few packaging related things:

* the dependency on haskell-src-exts says any version should do, but
the one shipped in Debian Sid
(http://packages.debian.org/sid/libghc6-src-exts-dev) doesn't do, so
some extra versioning info seems to be required
* I had to add an import of Distribution.Configuration to Main.hs to
get it to compile (it failed on the use of condTreeData).

/M

2008/10/5 Gwern Branwen [EMAIL PROTECTED]:
 On 2008.10.06 02:53:43 +1000, Ivan Miljenovic [EMAIL PROTECTED] scribbled 
 1.1K characters:
 I've now uploaded my SourceGraph program to Hackage [1].  It's rather
 simple at the moment, but if you pass in the .cabal file as a
 parameter (e.g. run it as SourceGraph Foo.cabal), it will create in
 the same directory as the .cabal file a Directory called SourceGraph
 that contains an html report of some basic graph-theoretic analysis of
 your code.

 The output format isn't ideal, but it should serve it's purpose for
 now (I'll fix it up and actually make it usable once my Thesis has
 been handed in).  What I'd appreciate if people could try it out and
 tell me if there's any code, etc. that it can't parse.  At the moment,
 it ignores all Data-based functions (e.g. class and instance
 declarations as well as record functions) and only looks at
 stand-alone functions (i.e. normal functions).

 SourceGraph requires version 0.3 of my Graphalyze library (version 0.2
 added the reports in, but had some bugs that 0.3 fixes).

 [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SourceGraph

 --
 Ivan Lazar Miljenovic

 SourceGraph looks pretty interesting. I don't think the output is that bad, 
 though. (If anyone is curious, attached is a tarball of what SourceGraph 
 generates for XMonad.)

 But I do have one or two problems:
 1) Didn't mention that it uses some executable 'dot', which Graphviz provides.
 2) Fails on XMonadContrib? While SourceGraph on XMonad finished in 1 or 2 
 seconds, SourceGraph xmonad-contrib.cabal has been running at 99% CPU (only 
 one CPU - I wonder if it could be parallelized) now for something over 3 
 hours. I know XMC is a bigger codebase than XM, but it's not thousands of 
 times bigger! :)

 --
 gwern
 Chicago ICE NSWG DSD 5926 RSA Chicago UFO MITM Lindows

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

 iEYEAREKAAYFAkjpI5AACgkQvpDo5Pfl1oKt9ACdEpMMFe7tooMFQXZMNoXrHY8P
 +kIAn1ctKk5aj9T8ThQwHIpHTQWiallf
 =CNNW
 -END PGP SIGNATURE-

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





-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Linux binary dist problems

2008-10-06 Thread Colin Fleming
Hi Chris,

Unfortunately that's not easy for me, I don't know exactly what the config
of the server is, and I use OSX at home. I could probably rig something up
using VMWare but that's a lot of work just to install the compiler. Another
option might be to create an unregisterised build, as detailed in the
porting guide, then use that to bootstrap a proper build. See:

http://hackage.haskell.org/trac/ghc/wiki/Building/Porting

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


[Haskell-cafe] Re: MPFR / FFI - Nefarious (Simple?) bug

2008-10-06 Thread Michal Konecny
Jared Updike wrote on  6 Oct 02:25:
 In order to create an arbitrary precision floating point / drop in
 replacement for Double, I'm trying to wrap MPFR
 (http://www.mpfr.org/)

Have you looked at:
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hmpfr

Michal
-- 
|o| Michal Konecny
|o|http://www-users.aston.ac.uk/~konecnym/
|o|office: (+42) (0)121 204 3462 
|o| PGP key http://www-users.aston.ac.uk/~konecnym/ki.aow


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


Re: [Haskell-cafe] Help me prove macid can scale! (Macid stress tests results for happs-tutorial toy job board disappointing so far.)

2008-10-06 Thread Thomas Hartman
There's a thread at happs group about this with good answers

http://groups.google.com/group/HAppS/browse_thread/thread/1031809dca26f349

My top post should probably have been a cc, apologies.

Looks pretty likely that the issues are solvable. Grokking the answers now.

thomas.


2008/10/6 Duncan Coutts [EMAIL PROTECTED]:
 On Sun, 2008-10-05 at 15:57 -0700, Jason Dusek wrote:
 I don't want to be contrarian, but I guess I can't help
   myself. Does MACID have anything to say about failover and
   replication? Isn't that more important than volume?

 HAppS does failover and replication within a cluster. They're working on
 sharding, but that's a good deal harder.

 Duncan


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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: SourceGraph-0.1 and Graphalyze-0.3

2008-10-06 Thread Niklas Broberg
  * the dependency on haskell-src-exts says any version should do, but
  the one shipped in Debian Sid
  (http://packages.debian.org/sid/libghc6-src-exts-dev) doesn't do, so
  some extra versioning info seems to be required

Ouch, that one's pretty old. Don't the wheels of debian packaging spin
faster than that? But yeah, it should be haskell-src-exts (= 0.3), to
avoid trying to dig up that should-be-long-dead-and-buried 0.2.1
version...

Cheers,

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


Re: [Haskell-cafe] Re: Hmm, what license to use?

2008-10-06 Thread david48
There's an article on slashdot about a developper that has a dilemna
with his BSD-licenced work, I thought that might be relevant to this
thread :

http://ask.slashdot.org/article.pl?sid=08/10/05/1317252
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simplifying a IsFunction type class using type equality constraints

2008-10-06 Thread Ryan Ingram
On Sat, Oct 4, 2008 at 2:58 AM, Corey O'Connor [EMAIL PROTECTED] wrote:
 I recently had a need to use the IsFunction typeclass described by Oleg here:
 http://okmij.org/ftp/Haskell/isFunction.lhs

 and am wondering if the use of the TypeCast class can be correctly
 replaced by a type equality constraint.

I noticed this as well; it seemed to work in my tests, although I
haven't seen any proof that they are equivalent.  The HList paper
mentions that the behavior of TypeCast is directly related to type
equality coercions in System F(C), GHC's core language.  So it's not
that surprising that it can be replaced with a type-equality
constraint, which is a more direct way of introducing the same
core-language code.

If you want to know for sure, you can look at the output of ghc
-ddump-simpl on each program.

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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: SourceGraph-0.1 and Graphalyze-0.3

2008-10-06 Thread Ivan Miljenovic
2008/10/6 Niklas Broberg [EMAIL PROTECTED]:
  * the dependency on haskell-src-exts says any version should do, but
  the one shipped in Debian Sid
  (http://packages.debian.org/sid/libghc6-src-exts-dev) doesn't do, so
  some extra versioning info seems to be required

 Ouch, that one's pretty old. Don't the wheels of debian packaging spin
 faster than that? But yeah, it should be haskell-src-exts (= 0.3), to
 avoid trying to dig up that should-be-long-dead-and-buried 0.2.1
 version...

 Cheers,

 /Niklas

OK, I'll try and fix those dependency issues in the next couple of
days.  I didn't specify a version of haskell-src-exts, as I couldn't
find any way of telling which versions were compatible (then again, I
was only able to work out how to use it and what everything meant by
reading the source directly...).

Gwern: I think I've found why it never ends on xmonad-contrib (it
happens for me here on the Grahpalyze library as well): when doing
clique/cycle detection, if a function recurses on itself more than
once (e.g. multiple pattern matches, each of which recurses) then the
clique detection at the very least goes nuts and tries creating an
infinite one-function clique.  This probably happens for cycles when
there's multiple edges between two functions.  I think the way to fix
this is to have a function that turns a graph into a simple graph
(i.e. no multiple edges or loops; well, maybe _one_ loop) and get the
clique detection, etc. routines use the output of that for processing.





-- 
Ivan Lazar Miljenovic
[EMAIL PROTECTED]
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: SourceGraph-0.1 and Graphalyze-0.3

2008-10-06 Thread Magnus Therning
On Mon, Oct 6, 2008 at 1:19 PM, Niklas Broberg [EMAIL PROTECTED] wrote:
  * the dependency on haskell-src-exts says any version should do, but
  the one shipped in Debian Sid
  (http://packages.debian.org/sid/libghc6-src-exts-dev) doesn't do, so
  some extra versioning info seems to be required

 Ouch, that one's pretty old. Don't the wheels of debian packaging spin
 faster than that? But yeah, it should be haskell-src-exts (= 0.3), to
 avoid trying to dig up that should-be-long-dead-and-buried 0.2.1
 version...

Yeah, I know.  I reported a bug against it and if I find the time
tonight I'll try to build an updated debian package.  Not sure what
the policy is ATM for NMUs though.

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Cale Gibbard
2008/10/6 Don Stewart [EMAIL PROTECTED]:
 dagit:
data and newtype vary in one more subtle way, and that's how/when they
evaluate to bottom.  Most of the time they behave identically, but in the
right cases they act sightly differently.  newtype is usually regarded as
more efficient than data.  This is because the compiler can choose to
optimize away the newtype so that it only exists at type check time.  I
think this is also possible with data in some, but not all, uses.

 The compiler *must* optimise away the use. They're sort of 'virtual'
 data, guaranteed to have no runtime cost.

I'm not sure that I'd want to be that emphatic about what an
implementation *must* do regarding something so operational.

The informal semantics of pattern matching in the Report says:

Matching the pattern con pat against a value, where con is a
constructor defined by newtype, depends on the value:
* If the value is of the form con v, then pat is matched against v.
* If the value is _|_, then pat is matched against _|_.
That is, constructors associated with newtype serve only to change the
type of a value.

This clearly has an implementation which introduces no overhead, which
one can expect from good implementations of the language. There are
obviously implementations of these semantics which do introduce
overhead as well though, so I would be hesitant to make any
requirement like that.

We can say however that newtypes have no additional runtime cost in
GHC regardless of the optimisation level you pick.

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


Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Arnar Birgisson
On Mon, Oct 6, 2008 at 14:58, Cale Gibbard [EMAIL PROTECTED] wrote:
 2008/10/6 Don Stewart [EMAIL PROTECTED]:
 dagit:
data and newtype vary in one more subtle way, and that's how/when they
evaluate to bottom.  Most of the time they behave identically, but in the
right cases they act sightly differently.  newtype is usually regarded as
more efficient than data.  This is because the compiler can choose to
optimize away the newtype so that it only exists at type check time.  I
think this is also possible with data in some, but not all, uses.

 The compiler *must* optimise away the use. They're sort of 'virtual'
 data, guaranteed to have no runtime cost.

 I'm not sure that I'd want to be that emphatic about what an
 implementation *must* do regarding something so operational.

 The informal semantics of pattern matching in the Report says:

 Matching the pattern con pat against a value, where con is a
 constructor defined by newtype, depends on the value:
* If the value is of the form con v, then pat is matched against v.
* If the value is _|_, then pat is matched against _|_.
 That is, constructors associated with newtype serve only to change the
 type of a value.

 This clearly has an implementation which introduces no overhead, which
 one can expect from good implementations of the language. There are
 obviously implementations of these semantics which do introduce
 overhead as well though, so I would be hesitant to make any
 requirement like that.

And this requirement is there why? Is it specifically put in so that
one is able to create this overhead-less implementation?

Given:

data A = A Int
newtype B = B Int

ta (A x) = True
tb (B x) = True

This happens (not surprisingly given your above comments):

*Main GOA :load test.hs
[1 of 1] Compiling Main ( test.hs, interpreted )
Ok, modules loaded: Main.
*Main GOA ta undefined
*** Exception: Prelude.undefined
*Main GOA tb undefined
True

Why is the x evaluated in ta?

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


Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Josef Svenningsson
On Mon, Oct 6, 2008 at 2:58 PM, Cale Gibbard [EMAIL PROTECTED] wrote:
 2008/10/6 Don Stewart [EMAIL PROTECTED]:
 dagit:
data and newtype vary in one more subtle way, and that's how/when they
evaluate to bottom.  Most of the time they behave identically, but in the
right cases they act sightly differently.  newtype is usually regarded as
more efficient than data.  This is because the compiler can choose to
optimize away the newtype so that it only exists at type check time.  I
think this is also possible with data in some, but not all, uses.

 The compiler *must* optimise away the use. They're sort of 'virtual'
 data, guaranteed to have no runtime cost.

 I'm not sure that I'd want to be that emphatic about what an
 implementation *must* do regarding something so operational.

 [..]

 We can say however that newtypes have no additional runtime cost in
 GHC regardless of the optimisation level you pick.

Not even that is true in general. One can in general end up doing
unnecessary work just for the sake of converting types.

Suppose you have a newtype Price = Price Int and you're given [Int]
and want to have [Price]. This is simple to do, just 'map Price'. But
since Price and Int are represented the same way this ought to be just
the identity function. But it is in general very difficult for a
compiler to figure out that this traversal of the list in fact is just
the identity function. Simple type conversions like these can
unfortunately force you to do some work even though the representation
is identical.

Cheers,

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


Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Ryan Ingram
On Mon, Oct 6, 2008 at 2:19 PM, Arnar Birgisson [EMAIL PROTECTED] wrote:
 And this requirement is there why? Is it specifically put in so that
 one is able to create this overhead-less implementation?

 Given:

 data A = A Int
 newtype B = B Int

 ta (A x) = True
 tb (B x) = True

 This happens (not surprisingly given your above comments):

 *Main GOA :load test.hs
 [1 of 1] Compiling Main ( test.hs, interpreted )
 Ok, modules loaded: Main.
 *Main GOA ta undefined
 *** Exception: Prelude.undefined
 *Main GOA tb undefined
 True

 Why is the x evaluated in ta?

x isn't evaluated.  undefined is evaluated to see if it matches the
constructor A.  But we don't even get to check, because undefined
throws an exception during its evaluation.

In the tb case, (B x) always matches because B is a newtype.  x gets
bound to undefined, but never evaluated.

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


Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Arnar Birgisson
Hi,

On Mon, Oct 6, 2008 at 16:10, Ryan Ingram [EMAIL PROTECTED] wrote:
 On Mon, Oct 6, 2008 at 2:19 PM, Arnar Birgisson [EMAIL PROTECTED] wrote:
 And this requirement is there why? Is it specifically put in so that
 one is able to create this overhead-less implementation?

 Given:

 data A = A Int
 newtype B = B Int

 ta (A x) = True
 tb (B x) = True

 This happens (not surprisingly given your above comments):

 *Main GOA :load test.hs
 [1 of 1] Compiling Main ( test.hs, interpreted )
 Ok, modules loaded: Main.
 *Main GOA ta undefined
 *** Exception: Prelude.undefined
 *Main GOA tb undefined
 True

 Why is the x evaluated in ta?

 x isn't evaluated.

Yes, realized my error just after hitting send :/

 undefined is evaluated to see if it matches the
 constructor A.  But we don't even get to check, because undefined
 throws an exception during its evaluation.

 In the tb case, (B x) always matches because B is a newtype.  x gets
 bound to undefined, but never evaluated.

And this happens because data values are basically pattern matched at
run-time but newtype values are matched at compile-time, effectively
turning tb into an Int - Bool function?

That explains pretty well why newtype can have only one constructor.

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


[Haskell-cafe] editing a Alex and Happy file

2008-10-06 Thread Manlio Perillo

Hi.

There is support for editing an Alex or Happy file?

I have seen some files that make use of tabs for layout (even Alex 
template files, and examples from both Alex and Happy), however tabs 
seems to be not recommended in Haskell.




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


Re: [Haskell-cafe] MPFR / FFI - Nefarious (Simple?) bug

2008-10-06 Thread Henning Thielemann


On Sun, 5 Oct 2008, Jared Updike wrote:


In order to create an arbitrary precision floating point / drop in
replacement for Double, I'm trying to wrap MPFR (http://www.mpfr.org/)
using the FFI but despite all my efforts the simplest bit of code
doesn't work.


Don't forget to add it to
  
http://haskell.org/haskellwiki/Libraries_and_tools/Mathematics#Real_and_rational_numbers
when you are ready.

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


[Haskell-cafe] I want my free (and good looking) parser!

2008-10-06 Thread Slavomir Kaslev
I am writing a Parsec parser for a C-like language and I have several datas that
look more or less like this one:

 import Control.Monad( liftM )
 import Text.ParserCombinators.Parsec

 data FooBar = Foo | Bar
 deriving (Show,Read,Bounded,Enum)

Looking at these, it seems that there should be no need to write a parser for
this guy by hand. We already know that it is bounded and enumerable, so we can
get a list of all possible FooBars:

 enumAll :: (Bounded a, Enum a) = [a]
 enumAll = enumFromTo minBound maxBound

Also, we know how to show and read each FooBar. Therefore, I should get a free
parser!

 freeParser :: (Enum a, Bounded a, Show a, Read a) = Parser a

Here is one use of freeParser:

 paramMod = option Foo freeParser
 test = parseTest $ do { x - paramMod; eof; return x }

Not suprisingly:
test Foo  = Foo
test Bar  = Bar
test  = Foo

I had a little hard time figuring out how this parser should look. The best I
came up with was:

 freeParser = freeParser' minBound
 where enumAll' :: (Bounded a, Enum a) = a - [a]
   enumAll' _ = enumAll
   freeParser' :: (Enum a, Bounded a, Show a, Read a) = a - Parser a
   freeParser' x = liftM read $ choice (map (string . show) (enumAll' 
 x))

[Actually, in my code I use reserved' (reserved' x = reserved x  return x)
instead of string, where reserved is from Parsec's builtin tokenizer (which does
some neat things behind the curtains). Here string is used just to
illustrate the
expamle.]

The problem is that freeParser, although useful, is far from elegant. It's
something that I came up with by trial and error. In short: it's a hack.

I would like to hear your suggestions about how it can be beautified.

Thank you in advance.

Cheers!

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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: SourceGraph-0.1 and Graphalyze-0.3

2008-10-06 Thread Iavor Diatchki
Hi all,
(this message is an ad:-)
For people interested in visualizing dependencies between the modules
in their project: on Hackage there is another simple tool called
graphmod that can generate a dot graph from your Haskell source
code.
-Iavor

2008/10/6 Magnus Therning [EMAIL PROTECTED]:
 On Mon, Oct 6, 2008 at 1:19 PM, Niklas Broberg [EMAIL PROTECTED] wrote:
  * the dependency on haskell-src-exts says any version should do, but
  the one shipped in Debian Sid
  (http://packages.debian.org/sid/libghc6-src-exts-dev) doesn't do, so
  some extra versioning info seems to be required

 Ouch, that one's pretty old. Don't the wheels of debian packaging spin
 faster than that? But yeah, it should be haskell-src-exts (= 0.3), to
 avoid trying to dig up that should-be-long-dead-and-buried 0.2.1
 version...

 Yeah, I know.  I reported a bug against it and if I find the time
 tonight I'll try to build an updated debian package.  Not sure what
 the policy is ATM for NMUs though.

 /M

 --
 Magnus Therning(OpenPGP: 0xAB4DFBA4)
 magnus@therning.org  Jabber: magnus@therning.org
 http://therning.org/magnus identi.ca|twitter: magthe

 ___
 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] MPFR / FFI - Nefarious (Simple?) bug

2008-10-06 Thread Aleš Bizjak

In order to create an arbitrary precision floating point / drop in
replacement for Double, I'm trying to wrap MPFR (http://www.mpfr.org/)
using the FFI but despite all my efforts the simplest bit of code
doesn't work. It compiles, it runs, but it crashes mockingly after
pretending to work for a while.


I've done an interface to MPFR. See Michal's message. It isn't  
particularly fast
but it works. You could improve/suggest improvements there, if you are  
interested.



Why does the C version work, but the Haskell version flake out?


I'm more or less guessing here, but it might have something to do with mpfr
calling __gmp_allocate_func in init2.c which is called inside  
mpfr_init_set_si, coupled
with what Judah Jacobson said. This is the only possible problem I can  
think of because
when using custom memory interface and allocating with malloc all the  
problems seem to disappear.


If you substitute your mpfr_set_signed_int for the one below, the noworks  
should become works.


mpfr_ptr mpf_set_signed_int(int x)
{
  mpfr_ptr result = mpf_new_mpfr();
  mp_limb_t * limb = malloc(mpfr_custom_get_size(mpfr_get_default_prec()));
  mpfr_custom_init(limb, mpfr_get_default_prec());
  mpfr_custom_init_set(result, MPFR_NAN_KIND, 0, mpfr_get_default_prec(),  
limb);

  if (result == NULL)
return NULL;
  mpfr_set_si(result, x, GMP_RNDN);
  return result;
}
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Ryan Ingram
On Mon, Oct 6, 2008 at 3:30 PM, Arnar Birgisson [EMAIL PROTECTED] wrote:
 undefined is evaluated to see if it matches the
 constructor A.  But we don't even get to check, because undefined
 throws an exception during its evaluation.

 In the tb case, (B x) always matches because B is a newtype.  x gets
 bound to undefined, but never evaluated.

 And this happens because data values are basically pattern matched at
 run-time but newtype values are matched at compile-time, effectively
 turning tb into an Int - Bool function?

Yep, that's exactly it.

 That explains pretty well why newtype can have only one constructor.

I never thought of it that way, but yes, it really does!

Also, you can get the same behavior out of ta if you write it like this:

ta ~(A x) = True

The translation looks something like this:

f ~(A x) = e
  =
f a = e
  where x = case a of (A v) - v  -- a,v fresh variables not mentioned in e

(or, equivalently)

f a = let (A x) = a in e -- a some fresh variable not mentioned in e

This delays the pattern-matching (and thus, the evaluation of a)
lazily until x is demanded, at which point a might throw an
exception or infinite loop, or, if the type has more than one
constructor, fail to pattern match (which also throws an exception).
If x is never demanded then neither is a.

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


[Haskell-cafe] Re: I want my free (and good looking) parser!

2008-10-06 Thread Christian Maeder
Slavomir Kaslev wrote:
 freeParser = freeParser' minBound
 where enumAll' :: (Bounded a, Enum a) = a - [a]
   enumAll' _ = enumAll
   freeParser' :: (Enum a, Bounded a, Show a, Read a) = a - Parser a
   freeParser' x = liftM read $ choice (map (string . show) (enumAll' 
 x))

1. I would use an explicit function argument instead of Show to allow
strings starting with lower case.

2. Calling read after parsing looks stupid. Just return the value shown
as parser result (within map).

3. Instead of the string parser, it should be checked if a further
alphaNum or '_' follows (for the longest match). And don't forget try!

Cheers Christian

 [Actually, in my code I use reserved' (reserved' x = reserved x  return x)
 instead of string, where reserved is from Parsec's builtin tokenizer (which 
 does
 some neat things behind the curtains). Here string is used just to
 illustrate the
 expamle.]
 
 The problem is that freeParser, although useful, is far from elegant. It's
 something that I came up with by trial and error. In short: it's a hack.
 
 I would like to hear your suggestions about how it can be beautified.
 
 Thank you in advance.
 
 Cheers!
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: I want my free (and good looking) parser!

2008-10-06 Thread Slavomir Kaslev
On Mon, Oct 6, 2008 at 8:07 PM, Christian Maeder
[EMAIL PROTECTED] wrote:
 Slavomir Kaslev wrote:
 freeParser = freeParser' minBound
 where enumAll' :: (Bounded a, Enum a) = a - [a]
   enumAll' _ = enumAll
   freeParser' :: (Enum a, Bounded a, Show a, Read a) = a - Parser 
 a
   freeParser' x = liftM read $ choice (map (string . show) 
 (enumAll' x))

 1. I would use an explicit function argument instead of Show to allow
 strings starting with lower case.


You are right. But that was not the problem. The problem was that I
wrestled with Haskell's type system quite a bit to make freeParser
work. What I want to write is

freeParser :: (Enum a, Bounded a, Show a, Read a) = Parser a
freeParser = liftM read $ choice (map (string . show) enumAll)

but it doesn't compile. How can I make this piece code work?

 2. Calling read after parsing looks stupid. Just return the value shown
 as parser result (within map).


Good point. It is silly =-)

 3. Instead of the string parser, it should be checked if a further
 alphaNum or '_' follows (for the longest match). And don't forget try!


Sure. I actually use Parsec's reserved, which is kind enough to manage
all this stuff for me.

 Cheers Christian

 [Actually, in my code I use reserved' (reserved' x = reserved x  return x)
 instead of string, where reserved is from Parsec's builtin tokenizer (which 
 does
 some neat things behind the curtains). Here string is used just to
 illustrate the
 expamle.]

 The problem is that freeParser, although useful, is far from elegant. It's
 something that I came up with by trial and error. In short: it's a hack.

 I would like to hear your suggestions about how it can be beautified.

 Thank you in advance.

 Cheers!





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


Re: [Haskell-cafe] Re: I want my free (and good looking) parser!

2008-10-06 Thread Jeremy Shaw
At Mon, 6 Oct 2008 20:20:57 +0300,
Slavomir Kaslev wrote:
 
 On Mon, Oct 6, 2008 at 8:07 PM, Christian Maeder
 [EMAIL PROTECTED] wrote:
  Slavomir Kaslev wrote:
  freeParser = freeParser' minBound
  where enumAll' :: (Bounded a, Enum a) = a - [a]
enumAll' _ = enumAll
freeParser' :: (Enum a, Bounded a, Show a, Read a) = a - 
  Parser a
freeParser' x = liftM read $ choice (map (string . show) 
  (enumAll' x))
 
  1. I would use an explicit function argument instead of Show to allow
  strings starting with lower case.
 
 
 You are right. But that was not the problem. The problem was that I
 wrestled with Haskell's type system quite a bit to make freeParser
 work. What I want to write is
 
 freeParser :: (Enum a, Bounded a, Show a, Read a) = Parser a
 freeParser = liftM read $ choice (map (string . show) enumAll)
 
 but it doesn't compile. How can I make this piece code work?

I would start by adding this to the top of the file:

 {-# LANGUAGE ScopedTypeVariables, FlexibleContexts  #-}

Then add 'forall a.' to the type signature of freeParser. This causes
freeParser' and freeParser to have the same value for 'a'. 

Now you can add an explicit type signature to (enumAll :: [a])

 freeParser :: forall a. (Enum a, Bounded a, Show a, Read a) = Parser a
 freeParser = freeParser' minBound
 where freeParser' :: (Enum a, Bounded a, Show a, Read a) = a - Parser a
   freeParser' x = liftM read $ choice (map (string . show) (enumAll 
 :: [a]))

The reseason you have to explicitly type enumAll is because you do a
show and then a read. Looking at a simplified case, we can see that
the types in this expression are ambigious:

 read (show 1.0)

show :: (Show a) = a - String
read :: (Read a) = String - a

It is perfectly valid typewise to do,:

 read (show 1.0) :: Char

Of course, that will result in a runtime error:

*Main read (show 1.0) :: Char
*** Exception: Prelude.read: no parse

If we rewrite freeParser like this, then we don't need any special extensions:

 freeParser :: (Enum a, Bounded a, Show a, Read a) = Parser a
 freeParser = freeParser' minBound
 where freeParser' :: (Enum a, Bounded a, Show a, Read a) = a - Parser a
   freeParser' x = choice (map (\x - string (show x)  return x) 
 enumAll)

Some might consider this prettier:

 freeParser :: (Enum a, Bounded a, Show a, Read a) = Parser a
 freeParser = freeParser' minBound
 where freeParser' :: (Enum a, Bounded a, Show a, Read a) = a - Parser a
   freeParser' x = choice [ string (show x)  return x | x - enumAll 
 ]

Anyway, there is another problem -- if you extend you datatype with a
constructor Foomatic:

 data FooBar = Foo | Foomatic | Bar
 deriving (Show,Read,Bounded,Enum)

you get the error:

test Foomatic
parse error at (line 1, column 4):
unexpected m
expecting end of input

This is because the parser wil successfully parse Foo and so it won't
even try parsing foomatic.

As a cheap hack we can do this:

 freeParser :: (Ord a, Enum a, Bounded a, Show a, Read a) = Parser a
 freeParser = freeParser' minBound
 where freeParser' :: (Ord a, Enum a, Bounded a, Show a, Read a) = a - 
 Parser a
   freeParser' x = choice [ try (string (show x))  return x | x - 
 reverse $ sort enumAll ]

We sort the constructors by reverse alphabetical order so that the
parser will try Foomatic before trying Foo. We also need to use the
'try' function so that if Foomatic fails it will still try Foo.

This is not a particularily efficient fix though.

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


Re: [Haskell-cafe] a really juvenile question .. hehehehe ;^)

2008-10-06 Thread Arnar Birgisson
On Mon, Oct 6, 2008 at 18:48, Ryan Ingram [EMAIL PROTECTED] wrote:
 Also, you can get the same behavior out of ta if you write it like this:

 ta ~(A x) = True

 The translation looks something like this:

 f ~(A x) = e
  =
 f a = e
  where x = case a of (A v) - v  -- a,v fresh variables not mentioned in e

 (or, equivalently)

 f a = let (A x) = a in e -- a some fresh variable not mentioned in e

 This delays the pattern-matching (and thus, the evaluation of a)
 lazily until x is demanded, at which point a might throw an
 exception or infinite loop, or, if the type has more than one
 constructor, fail to pattern match (which also throws an exception).
 If x is never demanded then neither is a.

Ah, that's pretty neat and subtle. Now, say I have a type created with
data that has only one constructor. Couldn't the compiler optimize
away this unneccessary evaluation during pattern matching? I.e. it
would make what you just wrote implicit in that case. Or perhaps data
declarations with just one ctor should really be turned into newtypes
by the programmer?

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


Re: [Haskell-cafe] MPFR / FFI - Nefarious (Simple?) bug

2008-10-06 Thread Jared Updike
  If you substitute your mpfr_set_signed_int for the one below, the noworks
 should become works.

Yes, this works perfectly. Thank you for saving my project! (Had I
known about HMPFR when I started this project, I would have just used
that instead of rolling my own, but it looks like HMPFR was uploaded
at the end of September though I started rolling my own bindings in
June or July... you know how life goes: work, moving, vacation, wife
starting grad school, etc.)

Last night I was seriously considering dropping work on my current
project and joining the effort to replace GMP in GHC as the only
solution. But now I

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


[Haskell-cafe] Inferred type is less polymorphic than expected, depends on order

2008-10-06 Thread Jason Dagit
Originally I sent this to glasgow-haskell where I was hoping someone by the
name of Simon would comment on the error message.  No one commented at all,
so I'm resending to haskell-cafe.  Thanks!

I was wondering if someone could help me understand why reordering the
case statements changes the type inference for this code.

1) I find the error message a bit confusing.
2) I don't understand why it's a problem in one order and not the
other.

I've tried to send this as literate haskell in hopes that you can just
copy and paste to a file and run the example.  This happens with or
without GADTs, this version doesn't have them but they don't turn out
to make any difference.

\begin{code}
{-# LANGUAGE ExistentialQuantification, RankNTypes #-}
module Main where

data Sealed a = forall x. Sealed (a x)
-- Or equivalently:
-- data Sealed a where
--   Sealed :: a x - Sealed a
\end{code}


Originally, I noticed this in a monad context...The original was much
more complicated.  But, we can simplify it even more, so keep reading.

goodOrder :: Monad m = (forall y z. p x y - q y z - q x z)
  - m (Sealed (p x)) - (forall b. m (Sealed (q b))) - m (Sealed
(q x))
goodOrder f mx my = do Sealed x - mx
   Sealed y - my
   return (Sealed (f x y))

badOrder :: Monad m = (forall y z. p x y - q y z - q x z)
 - m (Sealed (p x)) - (forall b. m (Sealed (q b))) - m (Sealed (q
x))
badOrder f mx my = do Sealed y - my
  Sealed x - mx
  return (Sealed (f x y))


Several helpful people in #haskell helped me converge on this greatly
simplified version below.

\begin{code}
f :: p x y - q y z - q x z
f = undefined
\end{code}

\begin{code}
badOrder :: (Sealed (p x)) - (forall b. (Sealed (q b))) - (Sealed (q x))
badOrder sx sy = case sy of
 Sealed y - case sx of
 Sealed x - Sealed (f x y)
\end{code}

\begin{code}
goodOrder :: (Sealed (p x)) - (forall b. (Sealed (q b))) - (Sealed (q x))
goodOrder sx sy = case sx of
  Sealed x - case sy of
  Sealed y - Sealed (f x y)
\end{code}


\begin{code}
main = return ()
\end{code}

This gives the error:
$ ghc --make Reorder.lhs
[1 of 1] Compiling Main ( Reorder.lhs, Reorder.o )

Reorder.lhs:52:29:
Inferred type is less polymorphic than expected
  Quantified type variable `x' is mentioned in the environment:
y :: q x x1 (bound at Reorder.lhs:51:24)
When checking an existential match that binds
x :: p x2 x
The pattern(s) have type(s): Sealed (p x2)
The body has type: Sealed (q x2)
In a case alternative: Sealed x - Sealed (f x y)
In the expression: case sx of Sealed x - Sealed (f x y)

After discussing this a bit, I think what may be happening in the
badOrder case is that the existentially bound type of x is bound after
the type `b' in the type of y, leading to the error message.

I would appreciate help understanding this, even if the help is, Go
read paper X, Y, and Z.

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


[Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread John Van Enk
Hello All,

I'm working on a Haskell based VPN. I can't think of any good names, so I'm
crowd sourcing it.

A few details that may help in naming it:
1. It's distributed (doesn't need a master or server).
2. It's secure (duh)
3. It uses TUN/TAP
4. It's written (mostly) in Haskell!

The best I can do is HaskVPN. This name is so bad I'm afraid to admit it. A
better suggestion would be much appreciated.

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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread Don Stewart
vanenkj:
Hello All,
 
I'm working on a Haskell based VPN. I can't think of any good names, so
I'm crowd sourcing it.
 
A few details that may help in naming it:
1. It's distributed (doesn't need a master or server).
2. It's secure (duh)
3. It uses TUN/TAP
4. It's written (mostly) in Haskell!
 
The best I can do is HaskVPN. This name is so bad I'm afraid to admit it.
A better suggestion would be much appreciated.

Is the code around somewhere? This sounds intriguing.

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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread wman
 The best I can do is HaskVPN. This name is so bad I'm afraid to admit
 it.
 A better suggestion would be much appreciated.


How about HaPN (pronounced as happen), obviously standing for Haskell
Private Network. Whether it's better is a matter of taste ;-)



 Is the code around somewhere? This sounds intriguing.

 -- Don


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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread Jason Dagit
2008/10/6 John Van Enk [EMAIL PROTECTED]

 Hello All,

 I'm working on a Haskell based VPN. I can't think of any good names, so I'm
 crowd sourcing it.

 A few details that may help in naming it:
 1. It's distributed (doesn't need a master or server).
 2. It's secure (duh)
 3. It uses TUN/TAP
 4. It's written (mostly) in Haskell!

 The best I can do is HaskVPN. This name is so bad I'm afraid to admit it. A
 better suggestion would be much appreciated.


My advice so to find something cute, like an animal, and use that in the
name instead of some implementation details like the programming language.

So you could be, WaterbearVPN, for example.  Okay, that was sort of a joke
as waterbears aren't really that cute, but I think you get the idea.

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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread Corey O'Connor
2008/10/6 wman [EMAIL PROTECTED]:
 How about HaPN (pronounced as happen), obviously standing for Haskell
 Private Network. Whether it's better is a matter of taste ;-)

+1 for HaPN
Quite catchy IMO. :-)

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


[Haskell-cafe] Darcs / Git

2008-10-06 Thread Dominic Steinitz
Not really a Haskell question but I'm not sure where else to go.

What's the preferred method of converting a darcs repository to git? And
is there a way of converting from git to darcs?

The reason I ask is that my colleague cannot get darcs to work on his
Windows box.

Thanks, Dominic.

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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread wman
And to be really original, try to sell some weird adjective with it. The
ubuntu crowd didn't buy this, so maybe you could make it Horny Hornet VPN
;-)

2008/10/6 Jason Dagit [EMAIL PROTECTED]


 My advice so to find something cute, like an animal, and use that in the
 name instead of some implementation details like the programming language.

 So you could be, WaterbearVPN, for example.  Okay, that was sort of a joke
 as waterbears aren't really that cute, but I think you get the idea.

 Jason


 ___
 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] Name for Haskell based VPN Client/Server

2008-10-06 Thread John Van Enk
On Mon, Oct 6, 2008 at 2:52 PM, Don Stewart [EMAIL PROTECTED] wrote:


 Is the code around somewhere? This sounds intriguing.

 -- Don


Yes! Though this is the Works For Me (alpha release) version.

Keep in mind:
* It's not cabalized yet, so... we use my quick-and-dirty build scripts to
build/clean.
* It's throughput runs at about 800KB/s over Wi-Fi (i should be able to get
this faster).
* Depends on the Data.Binary (binary)
* Depends on Network.Socket.ByteString (network-bytestring)
* Requires that you have the tun module loaded (make sure the /dev/net/tun
device exists)
* Needs to run as root (do you trust me?)
* UDP port is fixed at 24999 for now (remember, WFM alpha release)
* It uses a C file to do the ioctls and setup the IP address, MTU, etc...
(any one able to see a way to remove the C file? It's not doing anything all
that complex...)

Here's how to use it:

sudo ./haskvpn [my vpn ip] [address to bind to] [address to connect to]

Here's any example:

# On machine 1
sudo ./haskvpn 10.0.0.1 0.0.0.0 192.168.128.60

# On machine 2
sudo ./haskvpn 10.0.0.2 0.0.0.0 192.168.128.50

Once that comes up, you should be able to ping, ssh, etc from 10.0.0.1 to
10.0.0.2 and back again.

The code is here: http://sw17ch.com/code/haskvpn-1223320484.tar.gz

Once the code is downloaded, run ./build.sh and you (should) find the
haskvpn binary in the same directory.

There are 338 lines of haskell/c (including comments/whitespace), so it
shouldn't take too long to read over.

Reccomendations/patches/insults are requested!

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


Re: [Haskell-cafe] Darcs / Git

2008-10-06 Thread Jason Dagit
On Mon, Oct 6, 2008 at 12:11 PM, Dominic Steinitz 
[EMAIL PROTECTED] wrote:

 Not really a Haskell question but I'm not sure where else to go.


The best place to ask would be the darcs-users mailing list:
http://lists.osuosl.org/mailman/listinfo/darcs-users

What's the preferred method of converting a darcs repository to git? And
 is there a way of converting from git to darcs?


Never tried it personally, but I think tailor can do this:
http://progetti.arstecnica.it/tailor

The reason I ask is that my colleague cannot get darcs to work on his
 Windows box.


I think there are windows binaries floating around.  If you ask on the
darcs-users list I think someone can get this squared away for you.  Whether
you need help building or just getting binary that works.

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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread Anton van Straaten

Jason Dagit wrote:



2008/10/6 John Van Enk [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]

...

The best I can do is HaskVPN. This name is so bad I'm afraid to
admit it. A better suggestion would be much appreciated.


My advice so to find something cute, like an animal, and use that in the 
name instead of some implementation details like the programming language.


Or you could combine both cuteness and implementation details, with 
HaVPN, the mascot for which would be a lambdacat[*] saying:


  I can HaVPN?

Anton

[*] http://arcanux.org/lambdacats.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread John Van Enk
Ah, one more thing. It's not secure or distributed or any of the other
things I said yet. It's going to be. :) The version I just posted is able to
have two clients talk to each other (notice that neither of them is a
server).

I'll get the encryption and other details hammered in later. :)

On Mon, Oct 6, 2008 at 3:18 PM, John Van Enk [EMAIL PROTECTED] wrote:


 On Mon, Oct 6, 2008 at 2:52 PM, Don Stewart [EMAIL PROTECTED] wrote:


 Is the code around somewhere? This sounds intriguing.

 -- Don


 Yes! Though this is the Works For Me (alpha release) version.

 Keep in mind:
 * It's not cabalized yet, so... we use my quick-and-dirty build scripts to
 build/clean.
 * It's throughput runs at about 800KB/s over Wi-Fi (i should be able to get
 this faster).
 * Depends on the Data.Binary (binary)
 * Depends on Network.Socket.ByteString (network-bytestring)
 * Requires that you have the tun module loaded (make sure the /dev/net/tun
 device exists)
 * Needs to run as root (do you trust me?)
 * UDP port is fixed at 24999 for now (remember, WFM alpha release)
 * It uses a C file to do the ioctls and setup the IP address, MTU, etc...
 (any one able to see a way to remove the C file? It's not doing anything all
 that complex...)

 Here's how to use it:

 sudo ./haskvpn [my vpn ip] [address to bind to] [address to connect to]

 Here's any example:

 # On machine 1
 sudo ./haskvpn 10.0.0.1 0.0.0.0 192.168.128.60

 # On machine 2
 sudo ./haskvpn 10.0.0.2 0.0.0.0 192.168.128.50

 Once that comes up, you should be able to ping, ssh, etc from 10.0.0.1 to
 10.0.0.2 and back again.

 The code is here: http://sw17ch.com/code/haskvpn-1223320484.tar.gz

 Once the code is downloaded, run ./build.sh and you (should) find the
 haskvpn binary in the same directory.

 There are 338 lines of haskell/c (including comments/whitespace), so it
 shouldn't take too long to read over.

 Reccomendations/patches/insults are requested!

 --
 /jve




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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread John Van Enk
This is quite tempting, since my screen saver is a directory full of
lambdacats

On Mon, Oct 6, 2008 at 3:39 PM, Anton van Straaten
[EMAIL PROTECTED]wrote:

 Jason Dagit wrote:



 2008/10/6 John Van Enk [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]

 ...

The best I can do is HaskVPN. This name is so bad I'm afraid to
admit it. A better suggestion would be much appreciated.


 My advice so to find something cute, like an animal, and use that in the
 name instead of some implementation details like the programming language.


 Or you could combine both cuteness and implementation details, with
 HaVPN, the mascot for which would be a lambdacat[*] saying:

  I can HaVPN?

 Anton

 [*] http://arcanux.org/lambdacats.html

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




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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread wman
As far as insults go, one simply cannot go wrong with THE Shakespearean
insult kit ;-))

http://www.pangloss.com/seidel/shake_rule.html

2008/10/6 John Van Enk [EMAIL PROTECTED]


 On Mon, Oct 6, 2008 at 2:52 PM, Don Stewart [EMAIL PROTECTED] wrote:


 Is the code around somewhere? This sounds intriguing.

 -- Don


 Yes! Though this is the Works For Me (alpha release) version.

 Keep in mind:
 * It's not cabalized yet, so... we use my quick-and-dirty build scripts to
 build/clean.
 * It's throughput runs at about 800KB/s over Wi-Fi (i should be able to get
 this faster).
 * Depends on the Data.Binary (binary)
 * Depends on Network.Socket.ByteString (network-bytestring)
 * Requires that you have the tun module loaded (make sure the /dev/net/tun
 device exists)
 * Needs to run as root (do you trust me?)
 * UDP port is fixed at 24999 for now (remember, WFM alpha release)
 * It uses a C file to do the ioctls and setup the IP address, MTU, etc...
 (any one able to see a way to remove the C file? It's not doing anything all
 that complex...)

 Here's how to use it:

 sudo ./haskvpn [my vpn ip] [address to bind to] [address to connect to]

 Here's any example:

 # On machine 1
 sudo ./haskvpn 10.0.0.1 0.0.0.0 192.168.128.60

 # On machine 2
 sudo ./haskvpn 10.0.0.2 0.0.0.0 192.168.128.50

 Once that comes up, you should be able to ping, ssh, etc from 10.0.0.1 to
 10.0.0.2 and back again.

 The code is here: http://sw17ch.com/code/haskvpn-1223320484.tar.gz

 Once the code is downloaded, run ./build.sh and you (should) find the
 haskvpn binary in the same directory.

 There are 338 lines of haskell/c (including comments/whitespace), so it
 shouldn't take too long to read over.

 Reccomendations/patches/insults are requested!

 --
 /jve

 ___
 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] Re: [Haskell] ANNOUNCE: SourceGraph-0.1 and Graphalyze-0.3

2008-10-06 Thread Christopher Lane Hinson


I had this problem:

[EMAIL PROTECTED]:~/src/roguestar/rsagl (master)$ SourceGraph rsagl.cabal
dot: width (40671 = 32768) is too large.
dot: width (43275 = 32768) is too large.
dot: width (43720 = 32768) is too large.
dot: width (40525 = 32768) is too large.
Unable to generate report
[EMAIL PROTECTED]:~/src/roguestar/rsagl (master)$ dot -V
dot - Graphviz version 2.20.2 (Sat Aug 16 05:41:32 UTC 2008)

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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread Bulat Ziganshin
Hello John,

Monday, October 6, 2008, 10:29:09 PM, you wrote:

 I'm working on a Haskell based VPN. I can't think of any good names, so I'm 
 crowd sourcing it.

octopus? (it was a good serial about italian mafia spreading its
palpi all over the country :)


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Hoogle? [Stacking monads]

2008-10-06 Thread Andrew Coppin

Mitchell, Neil wrote:

Hi

  
Try doing a Hoogle search for c1 (c2 x) - c2 (c1 x). 
Hoogle correctly states that Data.Traversable.sequence will 
do it for you.


Now try doing c1 k (c2 x) - c2 (c1 k x). The 'sequence' 
function will also do this, but now Hoogle returns 0 results.


This is puzzling, since AFAIK, the above two type signatures 
are equvilent in some sense. (Specifically, replace every 
type X with type Y and you get from one to the other.) To me, 
this looks like a Hoogle bug. (It goes without saying that 
Hoogle also failed to find anything for the more specific 
type signature I was searching for, despite the fact that 
'sequence' unifies with it.)



Hoogle is not a unification engine - since that is very rarely what
people want out of a type search engine. What it is is an approximate
matcher. Let's compare the two types:

Your search :: c1 k (c2 x) - c2 (c1 k x)

sequence :: Monad m = [m a] - m [a]
  


Actually, I was thinking more along the lines of 
Data.Traversable.sequence, which has


 sequence :: (Traversable t, Monad m) = t (m a) - m (t a)


Are you expecting c1 (:: * - * - *) to unify with [] (:: * - *)? That
seems kind incorrect at the very last. Additionally, those types don't
look all that close.
  


Well, as I said, replacing one term with another transforms one 
signature into the other. I guess you can't curry type constructors as 
easily as functions - or at least, Hoogle currently doesn't like it.



But, let's briefly consider unification (and why Hoogle doesn't used
it). Consider the search:

Eq a = [(a,b)] - a - b

What the user wants is lookup, which sadly doesn't unify. However,
undefined unifies perfectly.
  


I see...

I notice that x - y doesn't unify with y - x in any way, shape or 
form, but Hoogle has absolutely no problem with that. What *does* Hoogle 
actually use for matching? Just a set of huristics and a metric for how 
similar two signatures are so it can order by approximate similarity? 
Or is it something more scientific than that?


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


Re: [Haskell-cafe] Monad transformers [Stacking monads]

2008-10-06 Thread Andrew Coppin

Andrew Coppin wrote:
I have some longwinded code that works, but I'm still thinking about 
how to do this more elegantly. It looks like what I really need is 
something like


 type M = StateT State (ResultSetT (ErrorT ErrorType Identity))

Is that the correct ordering?

If so, I guess that means I have to somehow construct ResultSetT. Is 
there an easy way to do that, given that I already have ResultSet? For 
example, if I put ResultSet into Traversable, would that let me do it?


...and again I'm talking to myself... :-/

So after much experimentation, I have managed to piece together the 
following facts:


- It appears that the outer-most monad transformer represents the 
inner-most monad. So StateT Foo ListT means a list of stateful 
computations, while ListT (StateT Foo) means a stateful list of 
computations.


- Each transformer seems to be defined as a newtype such that we have 
ListT :: m [x] - ListT m x and runListT :: ListT m x - m [x].


- By some magical process that I do not yet understand, I can wrap a 
StateT in 17 other transformers, and yet get and put do not require 
any lifting. (God only knows what happens if you were to use two StateTs 
in the same monad stack...)


What I haven't figured out yet is how to turn ResultSet into ResultSetT. 
I seem to just spend most of my time being frustrated by the type 
checker. A useful trick is to say things like


 :t lift (undefined :: ListT Int)

to figure out what type the various parts of a complex multi-monad 
expression have. (By now I'm seeing things like return . return . 
return, which is just far out.) But sometimes I find myself desperately 
wanting to take some block of code and say what type does *this* part 
of the expression have? or if I do x = y when y has *this* type, 
what type must x have? It can be very hard to work this out mentally, 
and unfortunately there isn't any tool I'm aware of that will help you 
in this matter.


After much testing, it appears that the utopian type definition at the 
very top of this message is in fact the thing I need. So if I can just 
figure out how to construct ResultSetT than I'm done. It looks like 
trying to build it from ResultSet is actually harder than just 
implementing it directly, so I'm going to try a direct transformer 
implementation instead. But it's seriously hard work!


For reference, I humbly present ResultSet.hs:



module Orphi.Kernel.ResultSet (ResultSet (), from_list, to_list, build, 
limit, cost, union) where


data ResultSet x = Pack {unpack :: [[x]]} deriving (Eq)

instance (Show x) = Show (ResultSet x) where
 show (Pack xss) = from_list  ++ show xss

instance Monad ResultSet where
 fail msg = Pack []
 return x = Pack [[x]]
 (Pack xss) = f = Pack $ raw_bind xss (unpack . f)

raw_bind :: [[x]] - (x - [[y]]) - [[y]]
raw_bind = work []
 where
   work out []   _ = out
   work out (xs:xss) f =
 let yss = foldr raw_union out (map f xs)
 in  if null yss
   then []   : work [] xss f
   else head yss : work (tail yss) xss f

raw_union :: [[x]] - [[x]] - [[x]]
raw_union []   yss  = yss
raw_union xss  []   = xss
raw_union (xs:xss) (ys:yss) = (xs ++ ys) : raw_union xss yss



from_list :: [[x]] - ResultSet x
from_list = Pack

to_list :: ResultSet x - [[x]]
to_list = unpack

build :: [x] - ResultSet x
build = from_list . map return

limit :: Int - ResultSet x - ResultSet x
limit n (Pack xss) = Pack (take n xss)

cost :: ResultSet x - ResultSet x
cost (Pack xss) = Pack ([]:xss)

union :: ResultSet x - ResultSet x - ResultSet x
union (Pack xss) (Pack yss) = Pack (raw_union xss yss)

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


Re: [Haskell-cafe] Inferred type is less polymorphic than expected, depends on order

2008-10-06 Thread Ryan Ingram
2008/10/6 Jason Dagit [EMAIL PROTECTED]:
 \begin{code}
 badOrder :: (Sealed (p x)) - (forall b. (Sealed (q b))) - (Sealed (q x))
 badOrder sx sy = case sy of
  Sealed y - case sx of
  Sealed x - Sealed (f x y)
 \end{code}

 \begin{code}
 goodOrder :: (Sealed (p x)) - (forall b. (Sealed (q b))) - (Sealed (q x))
 goodOrder sx sy = case sx of
   Sealed x - case sy of
   Sealed y - Sealed (f x y)
 \end{code}

It may help if you transform this a bit closer to System F with
existentials  datatypes:
/\ = forall
@t = type application, with the rule:

(a :: forall x. b) @t :: (replace occurrences of x in b with t)

-- the quantified type x gets packed into the data
-- and comes out when you pattern match on it
data Sealed s where
Sealed :: /\t. s t - Sealed s

goodOrder = \sx :: Sealed (p x) - \sy :: (/\b. Sealed (q b)) -
case sx of (Sealed @y pxy) -
case (sy @y) of (Sealed @z qyz) -
Sealed @z (f pxy qyz)

badOrder = \sx :: Sealed (p x) - \sy :: (/\b. Sealed (q b)) -
-- in order to pattern-match on sy, we need to give it a type
-- so we just pick an arbitrary type unknown or u distinct
from any other type we know about
case (sy @u) of (Sealed @z quz) -
case sx of (Sealed @y pxy) -
Sealed @z (f pxy quz) -- doesn't typecheck!

In the good order, you have already unpacked the existential for sx,
so you know what type to instantiate sy at.  In the bad order, you
don't know what type to instantiate sy at.

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


Re: [Haskell-cafe] Linux binary dist problems

2008-10-06 Thread Colin Fleming
Hi Marc,

Great, thanks for the pointer. I'll take a look at nix, that might be an
option. Thanks for the offer of server space too, but I'd really like to get
it going on my own space since I have domains and whatnot pointed there.

I also realise that the IDE support isn't there - it's even worse, I use
IntelliJ rather than Eclipse which is positively magical at times. Something
similar for a language like Haskell would be amazing.

Thanks for the advice!

Cheers,
Colin

2008/10/6 Marc Weber [EMAIL PROTECTED]

 Hi Colin,

 I only know about one other option:
 Try user mode linux / qemu / anotehr virtualziing software and setup the
 environment within that which you need... :-(
 Another thing you could try is installing nix (nixos.org) (software
 distirbution
 system).. It bootstraps current ghc via ghc-6.4.2 from binaries / source
 automatically (Don't think older compilers are supported than 6.4.x) but
 you'll get a complete copy of each system lib within the store
 direcotry. So you need some disk space.  And I can't guarantee that it
 works out of the box..  (it works with 2.6.9 kernel.. don't know about
 older ones)

 If all you want to do is toying around I can give you an ssh account to
 my server which has ghc installed.
 Anyway be prepared that there is no IDE support coming close to what
 Eclipse provides for the Java language..

 Sincerly
 Marc
 ___
 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] Inferred type is less polymorphic than expected, depends on order

2008-10-06 Thread Jason Dagit
On Mon, Oct 6, 2008 at 1:56 PM, Ryan Ingram [EMAIL PROTECTED] wrote:

 2008/10/6 Jason Dagit [EMAIL PROTECTED]:
  \begin{code}
  badOrder :: (Sealed (p x)) - (forall b. (Sealed (q b))) - (Sealed (q
 x))
  badOrder sx sy = case sy of
   Sealed y - case sx of
   Sealed x - Sealed (f x y)
  \end{code}
 
  \begin{code}
  goodOrder :: (Sealed (p x)) - (forall b. (Sealed (q b))) - (Sealed (q
 x))
  goodOrder sx sy = case sx of
Sealed x - case sy of
Sealed y - Sealed (f x y)
  \end{code}

 It may help if you transform this a bit closer to System F with
 existentials  datatypes:
 /\ = forall


Why is useful to replace forall with /\?



 @t = type application, with the rule:

 (a :: forall x. b) @t :: (replace occurrences of x in b with t)


How do you know how to apply this rule in general?

For example, (a :: forall x y. x - y) @t, would mean what?


 -- the quantified type x gets packed into the data
 -- and comes out when you pattern match on it
 data Sealed s where
Sealed :: /\t. s t - Sealed s


By 'x' you mean 't' right?

goodOrder = \sx :: Sealed (p x) - \sy :: (/\b. Sealed (q b)) -
case sx of (Sealed @y pxy) -
case (sy @y) of (Sealed @z qyz) -
Sealed @z (f pxy qyz)


You have the expression (Sealed @y pxy), but I don't understand what that
signifies.  Are you just saying that by doing a pattern match on 'sx' that
you're going to bind the existentially quantified variable to 'y'?  This
notation confuses me, but I can happily accept that we are binding the
existential type 'y' somewhere.

Assuming, I understand that, correctly, the expression (Sealed @z qyz) is
binding 'z' to an existential.  Why do you say, (sy @y).  What does that
mean?  That makes 'b' unify with 'y' that was bound in the first case?
goodOrder works as I expect, so I'm happy with this.

badOrder = \sx :: Sealed (p x) - \sy :: (/\b. Sealed (q b)) -
-- in order to pattern-match on sy, we need to give it a type
-- so we just pick an arbitrary type unknown or u distinct
 from any other type we know about
case (sy @u) of (Sealed @z quz) -
case sx of (Sealed @y pxy) -
Sealed @z (f pxy quz) -- doesn't typecheck!

 In the good order, you have already unpacked the existential for sx,
 so you know what type to instantiate sy at.  In the bad order, you
 don't know what type to instantiate sy at.


We instantiate 'u' to be the existential in sy.  OK.  But, my understanding
is that 'u' is unconstrained at this point, we said, forall b. Sealed (q b),
afterall.  So, when we bind 'y' in the second case, what prevents 'u' from
unifying with 'y'?

For what it's worth, in my real program where this came up, sy was created
by a recursive call like this:
foo :: Sealed (p x) - Sealed (q b)
foo = do
  p - blah
  q - foo
  return (Sealed (f p q))

Because the b doesn't appear on the LHS of the function arrow, I understand
it to have the same polymorphic properties as the 'forall b.' in the type
signature of goodOrder and badOrder.  Indeed, this example seems to
re-enforce that.  We had to reorder the binding of p and q to get this to
type check.

Thanks for the quick response,
Jason
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Inferred type is less polymorphic than expected, depends on order

2008-10-06 Thread Jason Dagit
On Mon, Oct 6, 2008 at 2:27 PM, Jason Dagit [EMAIL PROTECTED] wrote:


 For what it's worth, in my real program where this came up, sy was created
 by a recursive call like this:


I guess it should have been more like this:

blah :: Sealed (p x)
foo :: Sealed (q b)
foo = do
  p - blah
  q - foo
  return (Sealed (f p q))

Sorry for any confusion!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad transformers [Stacking monads]

2008-10-06 Thread Anton van Straaten

Andrew Coppin wrote:
If so, I guess that means I have to somehow construct ResultSetT. Is 
there an easy way to do that, given that I already have ResultSet? 


I haven't been following this thread closely, so forgive if this was 
already discussed, but my understanding is that the answer is no, in 
general.


In the paper Monad Transformers and Modular Interpreters[*], Section 8 
(Lifting Operations) touches on some of the issues.  That's from 1995 
- I don't know if any progress on this has been made since then, other 
than that a standard set of the most common monad transformers is now 
available.


Anton

[*] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.17.268

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


Re: [Haskell-cafe] Monad transformers [Stacking monads]

2008-10-06 Thread Reid Barton
Hi Andrew,

On Mon, Oct 06, 2008 at 09:48:51PM +0100, Andrew Coppin wrote:
 data ResultSet x = Pack {unpack :: [[x]]} deriving (Eq)

Your ResultSet monad is roughly equivalent to

newtype Nat = Nat Int
instance Monoid Nat where
  mempty = Nat 0
  (Nat x) `mappend` (Nat y) = Nat (x+y)
type ResultSet' = WriterT Nat []
-- ResultSet' x = [(x, Nat)]

where unpack :: ResultSet' x - [[x]] gives a list whose nth element
is the list of alternatives whose cost (Nat data) is n (with
trailing [] lists removed).  Except that using [[x]] internally lets
you be lazy about handling items of high cost.  (This is kind of neat
actually.)

I'd therefore guess that if there is an associated monad transformer
ResultSetT, it's similarly equivalent to

ResultSetT' m x = WriterT Nat (ListT m x)

where ListT is some version of ListT done right.  But on the other
hand, as I understand ListT done right, you can think of ListT m x
as a list of xs where you have to perform an action in the m monad
to get each successive value in the list.  The equivalence converting
ResultSet' to ResultSet sort of tears up the list in a way I'm not
sure is compatible with inserting a monad like that.


Once again, all this high-falutin' nonsense corresponds to really
concrete questions about what you want your code to *actually do*.
Consider your original problem

  run :: State - Foo - Either ErrorType (ResultSet State)

  run_and :: State - Foo - Foo - Either ErrorType (ResultSet State)
  {- some Either-ified version of
 run_and :: State - Foo - Foo - ResultSet State
 run_and s0 x y = do
   s1 - run s0 x
   s2 - run s1 y
   return s2
  -}

Say run s0 x returns many different possibilities s1 (with varying
costs).  And suppose run s1 y is a (Left err) for some of these s1 and
a (Right whatever) for others.  When should the overall result of
run_and be a Left and when should it be a Right?  And *which error*
should you return if there's more than one Left?  Do you really want
to check whether every run s1 y is a (Right whatever)?  In that case
you are not gaining much from the laziness of ResultSet and might as
well use ResultSet'.  Until you decide the answer to questions of this
kind, you can't know how to best structure your code.

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


[Haskell-cafe] I'll do USB in Haskell - tips?

2008-10-06 Thread Mauricio

Hi,

I'll need to use a lot of USB at work and, after
looking around, it seems there's no general USB
code done. 'libusb' and 'openusb' do not seem
ready enough so that wrapping them would be easier
than writing from scratch. (If you think I am
wrong until here and have time to write me your
opinion, I'll value it a lot.)

So: I would like to (try to) write a good
implementation of USB access in Haskell.  I would
like it to be really general, so that we could use
all of USB without need to resort to something
else; available to all possible environments and
operating systems; allow easy testing of USB
clients, maybe using fake USB devices that could
simulate problems; do that using Haskell code to
directly access operating system API.

I've read the appropriate chapters of USB 2.0
standard reference. I'll greatly appreciate any
information you can give me: sugestions on what
would be the Haskell way of doing USB; good
technical information on how USB is implemented in
different OSes; warnings on problems I may have;
wishes of good luck :)

I hope in one year I'll be able to post a message
here saying Haskell is the greatest language to
interface with USB devices.

Thanks,
Maurício

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


Re: [Haskell-cafe] Darcs / Git

2008-10-06 Thread Marc Weber
On Mon, Oct 06, 2008 at 08:11:21PM +0100, Dominic Steinitz wrote:
 Not really a Haskell question but I'm not sure where else to go.
 
 What's the preferred method of converting a darcs repository to git? And
 is there a way of converting from git to darcs?
 
 The reason I ask is that my colleague cannot get darcs to work on his
 Windows box.
If you have trouble you may also want to try the #darcs chat channel on
irc.freenode.net.. Those people want to help if they can.

You should also be able to find some info on haskell.org/ghc (use the search)
because of the recent discussion about switching to git for ghc
developement. By the way the cygwin git version did work best for me
(due to file permissions.. git gui does'nt work though - maybe I've
missed some options as well?)

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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread ajb

G'day all.

Quoting John Van Enk [EMAIL PROTECTED]:


I'm working on a Haskell based VPN. I can't think of any good names, so I'm
crowd sourcing it.


The naming of code is a difficult matter,
  It isn't just one of your LAN party games;
You may think at first I'm as mad as a hatter
When I tell you, your code must have THREE DIFFERENT NAMES.

First of all, there's the name that you use in publicity
  Such as Functional Forms, Nanocurses and HaRT,
Such as Proof General Kit, vector-space, and hinotify,
That will roll off the tongue and look good on slashdot.

But I tell you, your code needs a name that's evoking,
  A name that inhabits the package namespace.
Such as Text.PrettyPrint.HughesPJ, Data.ByteString,
That's easily typed when importing MixedCase.

But above and beyond, there's the name that's unique,
  And that is a name that is carefully picked.
The one that's so mangled it may well be Greek;
When it sits in slash-bin, it must never conflict.

It's the name that will cause most dissent with your peers,
  Far, far more than the task it is meant to perform.
It should work with your fingers, though not with your ears,
So de-vowel-ified acronym soup is the norm.

When you see a developer miffed and distracted,
  Tearing hair out in chunks or pacing without aim,
They are greatly afflicted by anger protracted,
Because somebody, somewhere, did not like the name.
  The simple, recognizable,
  Unrealizable,
Deep, unattainable, singular Name.

OK, having said that, I concur with those who have implicitly admitted
that there are too many H's in the names of Haskell programs.

I'd be tempted to pick a word starting with lan and put a v in front
of it.  My favourite VLANscape in particular.  It sounds professional,
and can be shortened to vlscape for the name of the executable.

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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread Brandon S. Allbery KF8NH

On 2008 Oct 6, at 20:56, [EMAIL PROTECTED] wrote:

Quoting John Van Enk [EMAIL PROTECTED]:
I'm working on a Haskell based VPN. I can't think of any good  
names, so I'm

crowd sourcing it.


(elided abuse of Old Possum)
I'd be tempted to pick a word starting with lan and put a v in  
front

of it.  My favourite VLANscape in particular.  It sounds professional,


I would advise against, as a VLAN is a very different beast from a VPN.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH


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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread John Van Enk
Hmm...

I like Securry, but I'm going to go ahead and shorten it to Scurry.
I also like HaPN a lot.

Any suggestions why either of these would be better than the other? Perhaps
a third party candidate would be more appropriate?

So...
1. Scurry
2. HaPN
3. ???

(bah, sorry Brandon, reply all, reply all reply all...)

On Mon, Oct 6, 2008 at 9:15 PM, Brandon S. Allbery KF8NH 
[EMAIL PROTECTED] wrote:

 On 2008 Oct 6, at 20:56, [EMAIL PROTECTED] wrote:

 Quoting John Van Enk [EMAIL PROTECTED]:

 I'm working on a Haskell based VPN. I can't think of any good names, so
 I'm
 crowd sourcing it.


 (elided abuse of Old Possum)
 I'd be tempted to pick a word starting with lan and put a v in front
 of it.  My favourite VLANscape in particular.  It sounds professional,


 I would advise against, as a VLAN is a very different beast from a VPN.

 --
 brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
 system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
 electrical and computer engineering, carnegie mellon universityKF8NH



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




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


Re: [Haskell-cafe] Darcs / Git

2008-10-06 Thread wman
the mingw git worked flawlessly for me (and will be certainly a lot less of
hassle, if one tries to remain cygwin-free). their version of git-gui also
works (i didn't test it extensively).

http://code.google.com/p/msysgit/

featuring an installer as well ;-)

as for darcs, look here:

http://wiki.darcs.net/DarcsWiki/CategoryBinaries#head-c7910dd98302946c671cf63cb62712589b392074

the darcsdir-w32 works fine without cygwin, just supply wget or curl ..

On Tue, Oct 7, 2008 at 1:55 AM, Marc Weber [EMAIL PROTECTED] wrote:

 On Mon, Oct 06, 2008 at 08:11:21PM +0100, Dominic Steinitz wrote:
  Not really a Haskell question but I'm not sure where else to go.
 
  What's the preferred method of converting a darcs repository to git? And
  is there a way of converting from git to darcs?
 
  The reason I ask is that my colleague cannot get darcs to work on his
  Windows box.
 If you have trouble you may also want to try the #darcs chat channel on
 irc.freenode.net.. Those people want to help if they can.

 You should also be able to find some info on haskell.org/ghc (use the
 search)
 because of the recent discussion about switching to git for ghc
 developement. By the way the cygwin git version did work best for me
 (due to file permissions.. git gui does'nt work though - maybe I've
 missed some options as well?)

 Marc
 ___
 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] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread Mike Coleman
Hi,

I could use a little help.  I was looking through the Real World
Haskell book and came across a trivial program for summing numbers in
a file.  They mentioned that that implementation was very slow, as
it's based on String's, so I thought I'd try my hand at converting it
to use lazy ByteString's.  I've made some progress, but now I'm a
little stuck because that module doesn't seem to have a 'read' method.

There's a readInt method, which I guess I could use, but it returns a
Maybe, and I don't see how I can easily strip that off.

So:

1.  Is there an easy way to strip off the Maybe that would allow an
equivalently concise definition for sumFile?  I can probably figure
out how to do it with pattern matching and a separate function--I'm
just wondering if there's a more concise way.

2.  Why doesn't ByteString implement 'read'?  Is it just that this
function (like 'input' in Python) isn't really very useful for real
programs?

3.  Why doesn't ByteString implement 'readDouble', etc.?  That is, why
are Int and Integer treated specially?  Do I not need readDouble?

Thanks,
Mike


-- lazy version (doesn't compile)

-- file: ch08/SumFile.hs

import qualified Data.ByteString.Lazy.Char8 as L

main = do
 contents - L.getContents
 print (sumFile contents)
 where sumFile = sum . map read . L.words
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread Jason Dagit
On Mon, Oct 6, 2008 at 7:06 PM, Mike Coleman [EMAIL PROTECTED] wrote:

 Hi,

 I could use a little help.  I was looking through the Real World
 Haskell book and came across a trivial program for summing numbers in
 a file.  They mentioned that that implementation was very slow, as
 it's based on String's, so I thought I'd try my hand at converting it
 to use lazy ByteString's.  I've made some progress, but now I'm a
 little stuck because that module doesn't seem to have a 'read' method.

 There's a readInt method, which I guess I could use, but it returns a
 Maybe, and I don't see how I can easily strip that off.

 So:

 1.  Is there an easy way to strip off the Maybe that would allow an
 equivalently concise definition for sumFile?  I can probably figure
 out how to do it with pattern matching and a separate function--I'm
 just wondering if there's a more concise way.


I'm not a ByteString expert, but there should be an easy way to solve this
issue of Maybe.

If you go to hoogle (http://www.haskell.org/hoogle/) and type this:
[Maybe a] - [a]
it says:
Data.Maybehttp://haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html
.catMaybeshttp://haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:catMaybes::
[Maybe
a] - 
[a]http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#v:catMaybes

As the top search result.

This means that you can convert any list of maybes into a list of what you
want.  It just tosses out the Nothings.



 2.  Why doesn't ByteString implement 'read'?  Is it just that this
 function (like 'input' in Python) isn't really very useful for real
 programs?


I think probably for things more complex than parsing ints it's best to make
your own parser?  I seem to recall that someone was working on a library of
parsing functions based on bytestring?  Maybe someone else can comment?

3.  Why doesn't ByteString implement 'readDouble', etc.?  That is, why
 are Int and Integer treated specially?  Do I not need readDouble?


I think readInt was mostly implemented because integer reading was needed a
lot for benchmarks and programming challenge sites and people noticed it was
way slower than needed so someone put in the effort it optimize it.  Once it
was optimized, that must have satisfied the need for fast number reading.

I would agree that at least for Prelude types it would be nice to have
efficient bytestring based parsers.  Do we have Read/Show classes
specifically for working in bytestrings?  Maybe that's what the world needs
in the bytestring api.  Then again, I'm not really qualified to comment :)
For all I know it already exists.

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


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread Daniel Fischer
Am Dienstag, 7. Oktober 2008 04:21 schrieb Jason Dagit:
 On Mon, Oct 6, 2008 at 7:06 PM, Mike Coleman [EMAIL PROTECTED] wrote:
  Hi,
 
  I could use a little help.  I was looking through the Real World
  Haskell book and came across a trivial program for summing numbers in
  a file.  They mentioned that that implementation was very slow, as
  it's based on String's, so I thought I'd try my hand at converting it
  to use lazy ByteString's.  I've made some progress, but now I'm a
  little stuck because that module doesn't seem to have a 'read' method.
 
  There's a readInt method, which I guess I could use, but it returns a
  Maybe, and I don't see how I can easily strip that off.
 
  So:
 
  1.  Is there an easy way to strip off the Maybe that would allow an
  equivalently concise definition for sumFile?  I can probably figure
  out how to do it with pattern matching and a separate function--I'm
  just wondering if there's a more concise way.

 I'm not a ByteString expert, but there should be an easy way to solve this
 issue of Maybe.

 If you go to hoogle (http://www.haskell.org/hoogle/) and type this:
 [Maybe a] - [a]
 it says:
 Data.Maybehttp://haskell.org/ghc/docs/latest/html/libraries/base/Data-Mayb
e.html
 .catMaybeshttp://haskell.org/ghc/docs/latest/html/libraries/base/Data-Mayb
e.html#v:catMaybes:: [Maybe
 a] -
 [a]http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html#
v:catMaybes

 As the top search result.

 This means that you can convert any list of maybes into a list of what you
 want.  It just tosses out the Nothings.

Since readInt returns a Maybe (Int,ByteString), Data.List.unfoldr would be a 
better fit for his needs.

The bytestring-lexing package 
(http://hackage.haskell.org/packages/archive/bytestring-lexing/0.1.2/doc/html/Data-ByteString-Lex-Double.html)
 
provides readDouble, which is also pretty fast, I think.


  2.  Why doesn't ByteString implement 'read'?  Is it just that this
  function (like 'input' in Python) isn't really very useful for real
  programs?

 I think probably for things more complex than parsing ints it's best to
 make your own parser?  I seem to recall that someone was working on a
 library of parsing functions based on bytestring?  Maybe someone else can
 comment?

At least parsec 3.0.0 has ByteString parsing modules (I've never used it, so I 
don't know how well they work).
IIRC, there's a plan to expand the bytestring-lexing package, too.


 3.  Why doesn't ByteString implement 'readDouble', etc.?  That is, why

  are Int and Integer treated specially?  Do I not need readDouble?

 I think readInt was mostly implemented because integer reading was needed a
 lot for benchmarks and programming challenge sites and people noticed it
 was way slower than needed so someone put in the effort it optimize it. 
 Once it was optimized, that must have satisfied the need for fast number
 reading.

More's underway, readDouble already delivered.

 I would agree that at least for Prelude types it would be nice to have
 efficient bytestring based parsers.  Do we have Read/Show classes
 specifically for working in bytestrings?  Maybe that's what the world needs
 in the bytestring api.  Then again, I'm not really qualified to comment :)
 For all I know it already exists.

partially.

 Jason

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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread Gwern Branwen
On 2008.10.06 21:19:17 -0400, John Van Enk [EMAIL PROTECTED] scribbled 4.3K 
characters:
Hmm...

I like Securry, but I'm going to go ahead and shorten it to Scurry.
I also like HaPN a lot.

Any suggestions why either of these would be better than the other? 
 Perhaps a third party
candidate would be more appropriate?

So...
1. Scurry
2. HaPN
3. ???

(bah, sorry Brandon, reply all, reply all reply all...)

Scurry has my vote. It is cute, it implies the software is busy and useful, it 
has the requisite subtle FP joke, and it doesn't seem to be already used.

--
gwern

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


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread wman
a slight modification to compile it :

change:
where sumFile = sum . map read . L.words
to :
where sumFile = sum . map (read . L.unpack) . L.words

but it's actually _slower_ than the non-bytestring version.

i did a little test, three versions of the same script and manufactured
meself  a ~50 MB file containing 1M of  ints 0-65535. and replaced the sum
with length for obvious reasons.

module Main where
import qualified Data.ByteString.Lazy.Char8 as L

main1 = do
contents - L.getContents
print (sumFile contents)
where sumFile = length . map L.readInt . L.words

main2 = do
contents - getContents
print (sumFile contents)
where sumFile = length . map (read :: String - Int) . words

main3 = do
contents - L.getContents
print (sumFile contents)
where sumFile = length . map ((read :: String - Int) .
L.unpack) . L.words

time main3  nums
real0m22.421s
user0m0.031s
sys 0m0.000s

time main2  nums
real0m14.296s
user0m0.015s
sys 0m0.016s

time main1  nums
real0m22.078s
user0m0.015s
sys 0m0.015s

i expected the conversions (L.unpack in main3) to kill the performance a
little, but not to make it nearly two times as slow.
and i certainly did not expect that even the version using the bytestring
readInt to be as slow  ...

did I do something wrong ?


On Tue, Oct 7, 2008 at 4:06 AM, Mike Coleman [EMAIL PROTECTED] wrote:

 Hi,

 I could use a little help.  I was looking through the Real World
 Haskell book and came across a trivial program for summing numbers in
 a file.  They mentioned that that implementation was very slow, as
 it's based on String's, so I thought I'd try my hand at converting it
 to use lazy ByteString's.  I've made some progress, but now I'm a
 little stuck because that module doesn't seem to have a 'read' method.

 There's a readInt method, which I guess I could use, but it returns a
 Maybe, and I don't see how I can easily strip that off.

 So:

 1.  Is there an easy way to strip off the Maybe that would allow an
 equivalently concise definition for sumFile?  I can probably figure
 out how to do it with pattern matching and a separate function--I'm
 just wondering if there's a more concise way.

 2.  Why doesn't ByteString implement 'read'?  Is it just that this
 function (like 'input' in Python) isn't really very useful for real
 programs?

 3.  Why doesn't ByteString implement 'readDouble', etc.?  That is, why
 are Int and Integer treated specially?  Do I not need readDouble?

 Thanks,
 Mike


 -- lazy version (doesn't compile)

 -- file: ch08/SumFile.hs

 import qualified Data.ByteString.Lazy.Char8 as L

 main = do
 contents - L.getContents
 print (sumFile contents)
 where sumFile = sum . map read . L.words
 ___
 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] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread Don Stewart
666wman:
a slight modification to compile it :
 
change:
where sumFile = sum . map read . L.words
to :
where sumFile = sum . map (read . L.unpack) . L.words
 
but it's actually _slower_ than the non-bytestring version.

Never unpack a bytestring.

import qualified Data.ByteString.Lazy.Char8 as S

main = print . go 0 = S.getContents
  where
go n s = case S.readInt s of
Nothing - n
Just (k,t)  - go (n+k) (S.tail t)

Assuming you're reading int, integers or doubles.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread Mike Coleman
Thanks for your replies.  Hoogle is pretty cool--I didn't know about that.

I ended up with this, which is pretty close to the original (it will
also bomb if given non-integer input):

import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.Maybe as M

main = do
 contents - L.getContents
 print (sumFile contents)
 where sumFile = sum . map (fst . M.fromJust . L.readInt) . L.words


One further problem I've encountered: My Haskell program runs under
'runghc', but I get a link error when compiling it (GHC 6.8.2, latest
Ubuntu).  Any suggestions?

$ ghc -o LazySumFile LazySumFile.hs
LazySumFile.o: In function `sOz_info':
(.text+0x200): undefined reference to
`bytestringzm0zi9zi0zi1_DataziByteStringziLazzyziChar8_readInt_closure'
LazySumFile.o: In function `sOF_info':
(.text+0x35d): undefined reference to
`bytestringzm0zi9zi0zi1_DataziByteStringziLazzyziChar8_words_closure'
LazySumFile.o: In function `sRF_info':
(.text+0x4d7): undefined reference to
`bytestringzm0zi9zi0zi1_DataziByteStringziLazzy_getContents_closure'
LazySumFile.o: In function `sRF_info':
(.text+0x64f): undefined reference to
`__stginit_bytestringzm0zi9zi0zi1_DataziByteStringziLazzyziChar8_'
LazySumFile.o: In function `sOF_srt':
(.data+0xa0): undefined reference to
`bytestringzm0zi9zi0zi1_DataziByteStringziLazzyziChar8_words_closure'
LazySumFile.o: In function `sOF_srt':
(.data+0xa8): undefined reference to
`bytestringzm0zi9zi0zi1_DataziByteStringziLazzyziChar8_readInt_closure'
LazySumFile.o: In function `rOh_closure':
(.data+0x110): undefined reference to
`bytestringzm0zi9zi0zi1_DataziByteStringziLazzy_getContents_closure'
collect2: ld returned 1 exit status
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] After upgrade bytestring to 0.9.1.3, my program cannot run.

2008-10-06 Thread Magicloud

Just a simple text process program. When I runhaskell it. I got:

GHCi runtime linker: fatal error: I found a duplicate definition for symbol
  fps_minimum
whilst processing object file
  ~/.cabal/lib/bytestring-0.9.1.3/ghc-6.8.3/HSbytestring-0.9.1.3.o
This could be caused by:
  * Loading two different object files which export the same symbol
  * Specifying the same object file twice on the GHCi command line
  * An incorrect `package.conf' entry, causing some object to be
loaded twice.
GHCi cannot safely continue in this situation.  Exiting now.  Sorry.

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


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread wman
the problem is that using readInt is actually _as slow_, at least using my
test script :-((

On Tue, Oct 7, 2008 at 5:12 AM, Don Stewart [EMAIL PROTECTED] wrote:

 666wman:
 a slight modification to compile it :
 
 change:
 where sumFile = sum . map read . L.words
 to :
 where sumFile = sum . map (read . L.unpack) . L.words
 
 but it's actually _slower_ than the non-bytestring version.

 Never unpack a bytestring.

import qualified Data.ByteString.Lazy.Char8 as S

main = print . go 0 = S.getContents
  where
go n s = case S.readInt s of
Nothing - n
Just (k,t)  - go (n+k) (S.tail t)

 Assuming you're reading int, integers or doubles.

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


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread Don Stewart
tutufan:
 Thanks for your replies.  Hoogle is pretty cool--I didn't know about that.
 
 I ended up with this, which is pretty close to the original (it will
 also bomb if given non-integer input):
 
 import qualified Data.ByteString.Lazy.Char8 as L
 import qualified Data.Maybe as M
 
 main = do
  contents - L.getContents
  print (sumFile contents)
  where sumFile = sum . map (fst . M.fromJust . L.readInt) . 
 L.words
 
 
 One further problem I've encountered: My Haskell program runs under
 'runghc', but I get a link error when compiling it (GHC 6.8.2, latest
 Ubuntu).  Any suggestions?

Oh wow, runghc is an interpreter. It is on average about 30x slower than
compiled code.

To compile, try something like:

ghc -O2 --make A.hs

And enjoy the native codes. :)

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


Re: [Haskell-cafe] After upgrade bytestring to 0.9.1.3, my program cannot run.

2008-10-06 Thread Don Stewart
magicloud.magiclouds:
 Just a simple text process program. When I runhaskell it. I got:
 
 GHCi runtime linker: fatal error: I found a duplicate definition for symbol
   fps_minimum
 whilst processing object file
   ~/.cabal/lib/bytestring-0.9.1.3/ghc-6.8.3/HSbytestring-0.9.1.3.o
 This could be caused by:
   * Loading two different object files which export the same symbol
   * Specifying the same object file twice on the GHCi command line
   * An incorrect `package.conf' entry, causing some object to be
 loaded twice.
 GHCi cannot safely continue in this situation.  Exiting now.  Sorry.
 

This likely means your program is using some package A, that has been
compiled against (and loading) old bytestring, but also loading the new
bytestring.

The solution is to recompile whatever your library 'A' is that is trying
to use the old bytestring.

Or try compiling it , with ghc --make

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


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread wman
new figures, after updating bytestring (0.9.0.1.1 - 0.9.1.2)  using -O2

time Main  nums
real0m2.531s
user0m0.015s
sys 0m0.015s

time Main2  nums
real0m13.999s
user0m0.015s
sys 0m0.015s

time Main3  nums
real0m2.796s
user0m0.015s
sys 0m0.015s

thats more like it, even the unpacking didn't hurt so much.

the morals: Thou shalt update your libraries  Thou shalt not forget to
turn on optimizations before bitching it's too slow ;-)))

thx

On Tue, Oct 7, 2008 at 5:19 AM, Don Stewart [EMAIL PROTECTED] wrote:

 Hmm. How are you compiling it? Using bytestring 0.9.1.x ?

 Should be fast,

 http://shootout.alioth.debian.org/gp4/benchmark.php?test=sumcollang=all

 Assuming you're turning on optimisations ( ghc -O2 )

 -- Don

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


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread Brandon S. Allbery KF8NH

On 2008 Oct 6, at 23:54, wman wrote:
just for the kicks i tried the new version of bytestring without -O2  
and the results were even worse:


Yep, ByteString does a lot of stuff that is really bad when GHC isn't  
performing stream fusion --- but when it is, the code compiles down to  
tight machine code that can rival C.


is there a reason why -O2 shouldn't be made the default (and  
allowing to turn off optimizations by -O0 perhaps) ?



-O2 breaks on some platforms, I think.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH


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


Re: [Haskell-cafe] Name for Haskell based VPN Client/Server

2008-10-06 Thread John Van Enk
I've settled on scurry. Those of you interested in seeing the cabalized
Works For Me Alpha version can check out the Google Code page below.

http://code.google.com/p/scurry/

Again, suggestions/comments/hatemail are encouraged.

/jve

On Mon, Oct 6, 2008 at 10:22 PM, Gwern Branwen [EMAIL PROTECTED] wrote:

 On 2008.10.06 21:19:17 -0400, John Van Enk [EMAIL PROTECTED] scribbled
 4.3K characters:
 Hmm...
 
 I like Securry, but I'm going to go ahead and shorten it to Scurry.
 I also like HaPN a lot.
 
 Any suggestions why either of these would be better than the other?
 Perhaps a third party
 candidate would be more appropriate?
 
 So...
 1. Scurry
 2. HaPN
 3. ???
 
 (bah, sorry Brandon, reply all, reply all reply all...)

 Scurry has my vote. It is cute, it implies the software is busy and useful,
 it has the requisite subtle FP joke, and it doesn't seem to be already used.

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

 iEYEAREKAAYFAkjqx90ACgkQvpDo5Pfl1oL8FwCfTSEW4BtCZM+wuWQiQ98NPCnv
 atEAnRXekljUuC9VKqnF+ixX+UiQXNSO
 =kk9h
 -END PGP SIGNATURE-




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


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread Don Stewart
666wman:
just for the kicks i tried the new version of bytestring without -O2 and
the results were even worse:

Note that without -O or -O2 no strictness analysis is performed. So that
tail recursive loop ... won't be. You could try -Onot -fstrictness just
for kicks, to see why strictness analysis is important when writing in a
tail recursive style.

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


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread wman
 ghc -Onot -fstrictness --make Main1.hs  ghc -Onot -fstrictness --make
Main2.hs  ghc -Onot -fstrictness --make Main3.hs

time Main1  nums
real0m39.530s
user0m0.015s
sys 0m0.030s

time Main2  nums
real0m14.078s
user0m0.015s
sys 0m0.015s

time Main3.exe  nums
real0m41.342s
user0m0.015s
sys 0m0.015s

still, i'm going to google up strictness analysis to at least know what made
no difference in this case ;-)

btw, why is the example #2 (
http://shootout.alioth.debian.org/gp4/benchmark.php?test=sumcollang=ghcid=2)
(which kicks collective asses of all other participants) not considered in
the shootout ? Too much optimizations ?

On Tue, Oct 7, 2008 at 6:27 AM, Don Stewart [EMAIL PROTECTED] wrote:

 666wman:
 just for the kicks i tried the new version of bytestring without -O2
 and
 the results were even worse:

 Note that without -O or -O2 no strictness analysis is performed. So that
 tail recursive loop ... won't be. You could try -Onot -fstrictness just
 for kicks, to see why strictness analysis is important when writing in a
 tail recursive style.

 -- Don

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


Re: [Haskell-cafe] newbie questions (read, etc., with Data.ByteString.Lazy.Char8)

2008-10-06 Thread Don Stewart
666wman:
ghc -Onot -fstrictness --make Main1.hs  ghc -Onot -fstrictness --make
Main2.hs  ghc -Onot -fstrictness --make Main3.hs
 
time Main1  nums
real0m39.530s
user0m0.015s
sys 0m0.030s
 
time Main2  nums
real0m14.078s
user0m0.015s
sys 0m0.015s
 
time Main3.exe  nums
real0m41.342s
user0m0.015s
sys 0m0.015s
 
still, i'm going to google up strictness analysis to at least know what
made no difference in this case ;-)

Oh, that's interesting. Did they actually recompile? (you used
-fforce-recomp). Otherwise, might be an idea to use hpaste.org to paste
teh Main1,2,3 source code, since I think people reading don't know what
is represented in each program at this point.

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


Re: [Haskell-cafe] I'll do USB in Haskell - tips?

2008-10-06 Thread Krzysztof Skrzętnicki
On Tue, Oct 7, 2008 at 01:55, Mauricio [EMAIL PROTECTED] wrote:
 Hi,

 I'll need to use a lot of USB at work and, after
 looking around, it seems there's no general USB
 code done. 'libusb' and 'openusb' do not seem
 ready enough so that wrapping them would be easier
 than writing from scratch. (If you think I am
 wrong until here and have time to write me your
 opinion, I'll value it a lot.)

Have a look at libusb version 1.0 API. It looks pretty promising:

http://libusb.wiki.sourceforge.net/Libusb1.0

All best

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