[Haskell-cafe] Haskell on your system? Information wanted!

2009-03-18 Thread Don Stewart
Hey all,

I noticed we didn't have an easy page to find out how to get hold of
the Haskell toolchain for various systems. So there's now a link from
haskell.org to (existing) pages on how to obtain Haskell on windows, mac
osx and linux and bsd.

If you're a distro maintainer for these systems, please consider adding
relevant pointers to the pages, so that users of these systems can find
all the info they need.

http://haskell.org/haskellwiki/Windows

http://haskell.org/haskellwiki/OSX

http://haskell.org/haskellwiki/GNU/Linux

http://haskell.org/haskellwiki/BSD

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


Re: [Haskell-cafe] symbolic evaluator for Haskell?

2009-03-18 Thread Sterling Clover

On Mar 18, 2009, at 1:40 AM, wren ng thornton wrote:



Lambdabot (on #haskell) has something similar using a type, Expr,  
to overload certain names, e.g.


koninkjefoldr f z [1..5]
lambdabot  f 1 (f 2 (f 3 (f 4 (f 5 z

It's a complete hack and isn't as sophisticated as what you're  
after, but it could serve as a basis for implementation ideas.



This is, I believe, essentially the simple-reflect package on Hackage:

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


At least two of lennart's libraries provide related functionality:
Traced: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ 
traced
and Data.Number.Symbolic in numbers: http://hackage.haskell.org/cgi- 
bin/hackage-scripts/package/numbers


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


[Haskell-cafe] OpenGL Linking Issue

2009-03-18 Thread Mark Spezzano
Hi,

 

I hope I’m posting to the right forum. 

 

I’ve got OpenGL up and running on my Windows Vista machine (finally!) and it
runs perfectly well under Eclipse, bringing up a window with a rendered
image as expected.

 

The only issue starts when I try to compile the program without Eclipse
(using GHC rather than GHCi like Eclipse does).

 

I type:

 

C:\Users\Mark\workspace2\OpenGLPractice\srcghc --make Test1.hs

 

And get the following output

 

Linking Test1.exe ...

C:\Program
Files\Haskell\GLUT-2.1.1.2\ghc-6.10.1/libHSGLUT-2.1.1.2.a(Extensions.

o):fake:(.text+0xcc): undefined reference to `glutgetprocaddr...@4'

collect2: ld returned 1 exit status

 

What’s happening here? Obviously it’s a linking issue, but I was wondering
whether I need to include some library or file or option to ghc so that it
links correctly.

 

Cheers,

 

Mark Spezzano

 


No virus found in this outgoing message.
Checked by AVG. 
Version: 7.5.557 / Virus Database: 270.11.18/2008 - Release Date: 17/03/2009
4:25 PM
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Query on list comprehension

2009-03-18 Thread Melanie_Green

What are the limitations of list comprehension. I want to use
listcomprehension to output the pattern below. So a mixture of a's and
newline characters. The part im stuck at is creating arguments in the
listcomprehension to stop at some point then execute next loop. Is it even
possible to create the pattern below purely from list comprehension.Thankyou
in advance. 

a
aa
aaa
-- 
View this message in context: 
http://www.nabble.com/Query-on-list-comprehension-tp22573574p22573574.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Query on list comprehension

2009-03-18 Thread Adrian Neumann

Use a nested list comprehension, for example

Prelude [['a'| i - [0..n]]++\n|n - [1..3]]
[aa\n,aaa\n,\n]



Am 18.03.2009 um 07:47 schrieb Melanie_Green:



What are the limitations of list comprehension. I want to use
listcomprehension to output the pattern below. So a mixture of a's and
newline characters. The part im stuck at is creating arguments in the
listcomprehension to stop at some point then execute next loop. Is  
it even
possible to create the pattern below purely from list  
comprehension.Thankyou

in advance.

a
aa
aaa
--
View this message in context: http://www.nabble.com/Query-on-list- 
comprehension-tp22573574p22573574.html
Sent from the Haskell - Haskell-Cafe mailing list archive at  
Nabble.com.


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




PGP.sig
Description: Signierter Teil der Nachricht
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] encoding for least fixpoint

2009-03-18 Thread Dan Doel
On Tuesday 17 March 2009 7:36:21 pm ben wrote:
 I am trying to understand the definition of (co)inductive types in
 Haskell. After reading the beginning of Vene's thesis [1] I was happy,
 because I understood the definition of the least fixpoint:

 newtype Mu f = In (f (Mu f)).

 But this definition coincides with his definition of the greatest fixpoint

 newtype Nu f = Wrap (f (Nu f)),

 which in reality is not true
 (e. g. for
 f x = a * x-- the 'stream functor'
 the type Mu f should be empty, isn't it?).

This is true in a categorical semantics where initial algebras and final 
coalbebras are distinct, like in a total language that gets its semantics from 
sets and total functions thereon. However, Haskell gets its semantics (modulo 
some potential weirdness in IO that people have been discussing lately) from 
categories of partial orders and monotone functions. It turns out that you can 
show that initial algebras and final coalgebras coincide in such a category, 
and so least and greatest fixed points are the same in Haskell (I don't know 
how to demonstrate this; my fairly cursory searching hasn't revealed any very 
good online references on DCPO categories and algebraic semantics), which is 
why there's no distinction in the data declaration (as opposed to, say, Agda).

 Then I stumbled over a blog entry of Shin-Cheng Mu [2] and from there
 over an article of Wadler [3], where the least fixpoint is encoded as

 Lfix X. F X  =  All X. (F X - X) - X.

 and the greatest fixpoint as

 Gfix X. F X  =  Exists X. (X - F X) * X.

 I would like to understand these definitions, or get an intuition about
 their meaning.
 Could somebody give some explanation or a pointer to a place where I can
 find one?

You can glean some of this from the initial algebra/final coalgebra 
definitions of (co)data. The least fixed point Mu F of F is an F-algebra, 
which means there's an operation:

  in : F (Mu F) - Mu F

And Mu F is initial in the category of F-algebras, which means that for any 
other F-algebra (X, f : F X - X), there's a unique algebra homomorphism:

  cata_f : Mu F - X

such that: cata_f . in = f . map cata_f. And you can finesse that in Haskell 
and with higher order functions and make it:

  cata :: forall x. (F x - x) - Mu F - x

And, I suppose, since initial algebras Mu F correspond uniquely with such 
parameterized algebra homomorphisms, you're safe in *representing* them as 
such, which gives you:

  Mu F ~ forall x. (F x - x) - x

which is what the Lfix equation gets you above.

In the other case you have final coalgebras Nu F, which come with a coalgebra 
operation:

  out : Nu F - F (Nu F)

and for any other F-coalgebra (X, f : X - F X), a unique homomorphism:

  ana_f : X - Nu F

which, parameterizing by f in the same way gets us:

  ana :: forall x. (x - F x) - x - Nu F

Which results in a Nu F this time. So suppose we took the definition:

  ana = C

for some Haskell constructor C. Well, that means we need a constructor with 
the type of ana, and that is exactly the existential:

  data Nu f = forall x. C (x - f x) x -- exists x. (x - F x) * x

which gets you the Gfix equation above.

I realize some of that was hand-wavey, and maybe someone with more expertise 
could flesh it out a bit, but hopefully that helps.

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


Re: [Haskell-cafe] OpenGL Linking Issue

2009-03-18 Thread Sean Lee
Hi Mark,

From what I remember -- I haven't used OpenGL for about a year -- you
need something like

ghc --make -package GLUT -lglut Test1.hs

assuming that you have both HOpenGL haskell package and OpenGL c library.


Cheers,
Sean

2009/3/18 Mark Spezzano mark.spezz...@chariot.net.au:
 Hi,



 I hope I’m posting to the right forum.



 I’ve got OpenGL up and running on my Windows Vista machine (finally!) and it
 runs perfectly well under Eclipse, bringing up a window with a rendered
 image as expected.



 The only issue starts when I try to compile the program without Eclipse
 (using GHC rather than GHCi like Eclipse does).



 I type:



 C:\Users\Mark\workspace2\OpenGLPractice\srcghc --make Test1.hs



 And get the following output



 Linking Test1.exe ...

 C:\Program
 Files\Haskell\GLUT-2.1.1.2\ghc-6.10.1/libHSGLUT-2.1.1.2.a(Extensions.

 o):fake:(.text+0xcc): undefined reference to `glutgetprocaddr...@4'

 collect2: ld returned 1 exit status



 What’s happening here? Obviously it’s a linking issue, but I was wondering
 whether I need to include some library or file or option to ghc so that it
 links correctly.



 Cheers,



 Mark Spezzano



 No virus found in this outgoing message.
 Checked by AVG.
 Version: 7.5.557 / Virus Database: 270.11.18/2008 - Release Date: 17/03/2009
 4:25 PM

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





-- 
Sean Lee
PhD Student
Programming Language and Systems Research Group
School of Computer Science and Engineering
University of New South Wales
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] encoding for least fixpoint

2009-03-18 Thread Ryan Ingram
On Tue, Mar 17, 2009 at 4:36 PM, ben benedikt.ahr...@gmx.net wrote:
 Then I stumbled over a blog entry of Shin-Cheng Mu [2] and from there
 over an article of Wadler [3], where the least fixpoint is encoded as

 Lfix X. F X  =  All X. (F X - X) - X.

 and the greatest fixpoint as

 Gfix X. F X  =  Exists X. (X - F X) * X.

 I would like to understand these definitions, or get an intuition about
 their meaning.

 Could somebody give some explanation or a pointer to a place where I can
 find one?

This is interesting.  So, there are two things going on.  First, we
only allow x to appear in positive form in f; for standard data
types in Haskell, this is equivalent to saying that you can write an
instance of Functor for f.  (I have an interesting proof of this which
I think I will write up for the Monad.Reader)

Once you have that, then you can get to defining fixed points on those
types.  Lfix encodes a fixed point by its fold.  For example, consider
this type:

 data Cell x xs = Nil | Cons x xs

Lfix (Cell a) is then equivalent to to (forall b. (Cell a b - b) -
b), which, if you expand the function argument by the case analysis on
Cell, you get (forall b. b - (a - b - b) - b); that is, foldr f z
xs = xs f z.

This is where the for free comes in to the description; it's like
the encoding of datatypes in System F without actual datatypes/case.
Let Pair a b be an abbreviation for forall c. (a - b - c), then
you have:

pair :: forall A B. a - b - Pair A B
pair = /\A B - \a b - /\C - \k - k a b

But in this case, instead of building simple datatypes, we are instead
building *recursive* datatypes, without actually requiring fixed
points in the language!

Gfix is similar, but instead of encoding a type by its fold, it
encodes it as a state machine.  So a Gfix ((,) Integer) stream of the
natural numbers could look something like this:  Gfix (\x - (x, x+1))
0; the first element of the pair is the stream result, and the second
is the existential state which is used to generate the next pair.

For reference, here's some code implementing this concept.  Keep in
mind that we are working in a subset of Haskell without fixed points;
so no recursion is allowed.

{-# LANGUAGE ExistentialQuantification, RankNTypes #-}
module FixTypes where

newtype Lfix f = Lfix (forall x. (f x - x) - x)

l_in :: Functor f = f (Lfix f) - Lfix f
l_in fl = Lfix (\k - k (fmap (\(Lfix j) - j k) fl))
-- derivation of l_in was complicated!

-- l_out :: Functor f = Lfix f - f (Lfix f)

instance Functor (Either a) where
   fmap f (Left a) = Left a
   fmap f (Right x) = Right (f x)

test_l :: Lfix (Either Int)
test_l = Lfix (\k - k $ Right $ k $ Right $ k $ Left 2)


data Gfix f = forall x. Gfix (x - f x) x

g_out :: Functor f = Gfix f - f (Gfix f)
g_out (Gfix f s) = fmap (\x - Gfix f x) (f s)

-- g_in :: Functor f = f (Gfix f) - Gfix f

instance Functor ((,) a) where
   fmap f ~(a,x) = (a, f x)

test_g :: Gfix ((,) Integer)
test_g = Gfix (\x - (x, x+1)) 0

 [3]http://homepages.inf.ed.ac.uk/wadler/papers/free-rectypes/free-rectypes.txt

There's something from Wadler's draft that doesn't make sense to me.  He says:

 This introduces a new type, T = Lfix X. F X, satisfying the isomorphism
 T ~ F T.  Note that it is an isomorphism, not an equality:  the type
 comes equipped with functions in : T - F T and out : F T - T.

While I was able to derive in for Lfix, and out for Gfix, I don't
think it's possible to derive a generic out for Lfix or in for
Gfix; maybe such a function *can* always be generated (specific to a
particular type), but I don't think it's possible to do so while just
relying on Functor.  Perhaps stronger generic programming methods are
necessary.

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


[Haskell-cafe] Re: Haskell Logo Voting has started!

2009-03-18 Thread Benjamin L . Russell
On Tue, 17 Mar 2009 15:24:28 +0100, Heinrich Apfelmus
apfel...@quantentunnel.de wrote:

[...]

Thanks for organizing this, finally I can choose ... Oh my god! How am I
supposed to make a vote?

Actually, I found the voting process to be fairly straightforward and
trivial.

Just go through the list, choose your top favorite, and assign rank 1
to it; then go through the rest of the list, choose your second
favorite, and assign rank 2 to it; similarly, repeat until you don't
see any more that you like.

Each time you assign a rank to a choice, the choice gets sorted to the
proper rank location from the top.

Then, optionally, choose all the ones that you don't dislike, and give
them rank 112 (I skipped this step because I didn't care about any of
the ones that I didn't like, and because I was too tired from
comparing all the ones that I did like).

Finally, leave all the rest with rank 113.

The process can take some time, especially at the beginning, since
each remaining choice must be compared with all other remaining
choices, but is quite thorough.

I picked my choices in stages, over a series of time periods, because
the entire list was too long to process in one sitting.

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

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


[Haskell-cafe] Re: Haskell Logo Voting has started!

2009-03-18 Thread Benjamin L . Russell
On Tue, 17 Mar 2009 21:58:12 +0100, Karel Gardas
karel.gar...@centrum.cz wrote:


Sorry for newcomer silly question, but where is the voting page located?

Each voter is assigned a private URL encoding a key for voting.  You
should have receive a vote in a message entitled CIVS Poll now
available for voting: Haskell Logo Competition from Eelco Lempsink,
the CIVS poll supervisor, at your e-mail address; if not, ask Lempsink
to resend it to you (you can find his e-mail address in his message at
the top of this thread).

A list of the logos on which to vote is available at
http://www.haskell.org/logos/poll.html.  You may find it convenient to
keep this page open in a separate tab in your browser when voting.

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

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


[Haskell-cafe] Re: Go Haskell!

2009-03-18 Thread Simon Marlow
I finally got around to making my code for random Go playouts available. 
Here it is:


  http://www.haskell.org/~simonmar/goboard.tar.gz

If someone were to make a nice library API on top of this and upload it to 
hackage, I'd be delighted.  Hack away.


Cheers,
Simon

Simon Marlow wrote:

Claus Reinke wrote:

Do you have an example of a mutable state/ IO bound application, like,
hmm, a window manager or a revision control system or a file system...?


If you're looking for a challenge, how about this one (there used to
be lots of Haskellers into this game, any of you still around?-):

http://computer-go.org/pipermail/computer-go/2008-October/016680.html


[ catching up with old haskell-cafe email ]

Interestingly, I did this a while ago.  Here's my results:

$ ./Bench 1 10
b: 14840, w: 17143 mercy: 67982
elapsed time: 3.42s
playouts/sec: 29208


so, nearly 30k/sec random playouts on 9x9.  That's using a hack that 
stops the game when the score is heavily in favour of one player, it 
drops to around 20k/sec with that turned off.


Not bad, but probably I'd guess an order of magnitude worse than you can 
do in tightly-coded C.  The Haskell implementation isn't nice, as you 
predicted.  Also the code is derived from some non-free internal MS 
code, so unfortunately I can't share it (but I could perhaps extract the 
free bits if anyone is really interested).


W wins slightly more often I think because komi 5.5 on a 9x9 board is a 
tad high.


It does parallelise too, of course:

$ ./Bench 8 10 +RTS -N8
b: 14872, w: 17488 mercy: 67584
elapsed time: 1.00s
playouts/sec: 99908

though still room for improvement there.

Cheers,
Simon


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


Re: [Haskell-cafe] encoding for least fixpoint

2009-03-18 Thread Duncan Coutts
On Wed, 2009-03-18 at 03:22 -0400, Dan Doel wrote:
 On Tuesday 17 March 2009 7:36:21 pm ben wrote:
  I am trying to understand the definition of (co)inductive types in
  Haskell. After reading the beginning of Vene's thesis [1] I was happy,
  because I understood the definition of the least fixpoint:
 
  newtype Mu f = In (f (Mu f)).
 
  But this definition coincides with his definition of the greatest fixpoint
 
  newtype Nu f = Wrap (f (Nu f)),
 
  which in reality is not true
  (e. g. for
  f x = a * x-- the 'stream functor'
  the type Mu f should be empty, isn't it?).
 
 This is true in a categorical semantics where initial algebras and final 
 coalbebras are distinct, like in a total language that gets its semantics 
 from 
 sets and total functions thereon. However, Haskell gets its semantics (modulo 
 some potential weirdness in IO that people have been discussing lately) from 
 categories of partial orders and monotone functions. It turns out that you 
 can 
 show that initial algebras and final coalgebras coincide in such a category, 
 and so least and greatest fixed points are the same in Haskell (I don't know 
 how to demonstrate this; my fairly cursory searching hasn't revealed any very 
 good online references on DCPO categories and algebraic semantics), which is 
 why there's no distinction in the data declaration (as opposed to, say, Agda).

You can explain it to yourself (not a proof) by writing out the example
for lists and co-lists along with fold for the list and unfold function
for the co-list. Then write conversion functions between them. You can
go from lists to co-lists using fold or unfold, but going from co-list
to list requires general recursion. And that's the key of course. In
Agda or something that distinguishes inductive and co-inductive types
you could do the first two conversions but not the conversion in the
other direction.

Duncan

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


[Haskell-cafe] Who generates Haskell code and uses type information at runtime?

2009-03-18 Thread Martin Hofmann
I try to modify Haskell code, parsed from an external source, at
runtime. Therefore I need type information about this code. Sometimes to
this is referred to as treating data as code and code as data. In
homoiconic languages such as Lisp this would be less cumbersome, but in
Haskell this seems to be not trivial.

Therefore I would like to know how other people solved this. Do you, for
example, 

  * use ghc-as-api and manipulate the code snippet in GHC's core
language?
  * use Language.Haskell.Syntax or Language.Haskell.TH and get your
type information via IO (from Hint or ghc) as a String?
  * use your own language representation for code and type and use a
tailored type inference/unification algorithm?
  * use your own language representation combined with Data.Typeable
and Data.Dynamics, but what about polymorphic types?
  * ...?

Thanks a lot,

Martin



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


[Haskell-cafe] Re: categories and monoids

2009-03-18 Thread Wolfgang Jeltsch
Am Dienstag, 17. März 2009 16:32 schrieben Sie:
 On Tue, 2009-03-17 at 13:06 +0100, Wolfgang Jeltsch wrote:
  A category is not a “generalized monoid” but categories (as a concept)
  are a generalization of monoids. Each category is a monoid, but not the
  other way round.

 You mean ``each monoid is a category, but not the other way round''.

Exactly. :-) 

  What is a monoid with many objects?

 A categorical definition of a monoid (that is, a plain old boring monoid
 in Set) is that it is a category with a single object.  A category is
 thus a monoid with the restriction to a single object lifted :) 

Okay. Well, a monoid with many objects isn’t a monoid anymore since a monoid 
has only one object. It’s the same as with: “A ring is a field whose 
multiplication has no inverse.” One usually knows what is meant with this but 
it’s actually wrong. Wrong for two reasons: First, because the multiplication 
of a field has an inverse. Second, because the multiplication of a ring is 
not forced to have no inverse but may have one.

It reminds me of a definition of “constant” in programming languages which 
occured in some literature: “A constant is a variable whose value cannot be 
changed.” :-) 

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


[Haskell-cafe] Re: categories and monoids

2009-03-18 Thread Wolfgang Jeltsch
Am Dienstag, 17. März 2009 18:43 schrieben Sie:
 On Tue, Mar 17, 2009 at 5:06 AM, Wolfgang Jeltsch

 g9ks1...@acme.softbase.org wrote:
  What is a “generalized monoid”? According to the grammatical construction
  (adjective plus noun), it should be a special kind of monoid

 There's no such implication in English. The standard example used by
 linguists is fake gun.

Okay, but this is a corner case isn’t it?

And the phrase “generalized monoid” has another problem. It’s not a single 
monoid that is generalized but the “monoid concept”. The class of monoids is 
extended to become the class of categories.

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


[Haskell-cafe] Re: Query on list comprehension

2009-03-18 Thread Jon Fairbairn
Melanie_Green jac_legend_...@hotmail.com writes:

 What are the limitations of list comprehension. I want to use
 listcomprehension to output the pattern below. So a mixture of a's and
 newline characters. The part im stuck at is creating arguments in the
 listcomprehension to stop at some point then execute next loop. Is it even
 possible to create the pattern below purely from list comprehension.Thankyou
 in advance. 

 a
 aa
 aaa

I'm not clear what you mean by the question. Why do you want
to use list comprehensions? What if they aren't the best way
of getting the result you want?

You can write 

[a | b - [replicate n 'a' | n - [1..]], a - b ++ \n] 

but does that replicate fail to meet your specification?
If not, you can replace it with another list comprehension
like this:

[a | b - [['a'| m - [1..n]] | n - [1..]], a - b ++ \n]

but at this point, comprehension is not what most people
would get from reading the code. I'd say it was clearer to
write

concat [replicate n 'a' ++ \n | n - [1..]]





-- 
Jón Fairbairn jon.fairba...@cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2009-01-31)

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


Re: [Haskell-cafe] Re: categories and monoids

2009-03-18 Thread Wolfgang Jeltsch
Am Mittwoch, 18. März 2009 05:36 schrieb wren ng thornton:
 Wolfgang Jeltsch wrote:
  Am Dienstag, 17. März 2009 10:54 schrieben Sie:
   I'm reading the Barr/Wells slides at the moment, and they say the
   following:
  
   Thus a category can be regarded as a generalized monoid,
 
  What is a “generalized monoid”? According to the grammatical construction
  (adjective plus noun), it should be a special kind of monoid, like a
  commutative monoid is a special kind of monoid. But then, monoids would
  be the more general concept and categories the special case, quite the
  opposite of how it really is.

 Usually in math texts a Y is a generalized X means exactly Ys are a
 generalization of Xs, and thus Y is the larger class of objects got by
 relaxing some law in X. It's a description, not a name. E.g. Hilbert
 space is a generalized Euclidean space, Heyting algebras are generalized
 Boolean algebras, modules are generalized vector spaces, etc.

I know these phrases but I always considered them as something, mathematicians 
use when they talk to each other informally, not what they would write in a 
book.

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


Re: [Haskell-cafe] Type equality proof

2009-03-18 Thread Wolfgang Jeltsch
Am Dienstag, 17. März 2009 21:51 schrieben Sie:
 On Tue, Mar 17, 2009 at 6:14 AM, Wolfgang Jeltsch wrote:
  Am Dienstag, 17. März 2009 11:49 schrieb Yandex:
   data (a :=: a') where
 Refl :: a :=: a
 Comm :: (a :=: a') - (a' :=: a)
 Trans :: (a :=: a') - (a' :=: a'') - (a :=: a'')
 
  I don’t think, Comm and Trans should go into the data type. They are not
  axioms but can be proven. Refl says that each type equals itself. Since
  GADTs are closed, Martijn’s definition also says that two types can *only*
  be equal if they are actually the same.
 
  Here are the original definition and the proofs of comm and trans.
  Compiles fine with GHC 6.10.1.
 
 data (a :=: a') where
 
 Refl :: a :=: a
 
 comm :: (a :=: a') - (a' :=: a)
 comm Refl = Refl
 
 trans :: (a :=: a') - (a' :=: a'') - (a :=: a'')
 trans Refl Refl = Refl

 These two theorems should be in the package.

But they should not be data constructors.

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


Re: [Haskell-cafe] Who generates Haskell code and uses type information at runtime?

2009-03-18 Thread Martin Hofmann
 GHC is the current state of the art, which will give you a full
 Haskell AST enriched with type information. You can then just modify the 
 AST directly.

I experimented with the AST from HscTypes.CoreModule in the ghc api.
However, it seems that this representation is too far away from my
theory. I would prefer something similar as Template Haskell.

 The ghc-api is somewhat sparsely documented

That might be the reason, why I have not seen how it can help me.

 It really depends on what you are trying to do...

Putting in a nutshell, I generalize an extensional defined function
definition into a recursive one. This is done in a number of steps by
modifying expressions and exploiting type information of
sub-expressions. For example: 

rev [] = []
rev [a] = [a]
rev [a,b] = [b,a]
rev [a,b,c] = [c,b,a]

~~

rev x = y

~~

rev [] = []
rev (x:xs) = (y:ys)

~~

rev [] = []
rev (x:xs) = (last (x:xs)) : (reverse (x:xs))


The initial set of rules is given by the user (in a file, via IO, ...).
The problem later is to infer the type of an intermediate variable, e.g.
'y'.

Thanks,

Martin

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


Re: [Haskell-cafe] Re: Haskell Logo Voting has started!

2009-03-18 Thread Wolfgang Jeltsch
Am Dienstag, 17. März 2009 16:55 schrieb Eelco Lempsink:
 We'll see.  Worst case: nobody votes (with 123 votes at this moment, I
 don't think that will be the problem).  Second worst case: most people
 don't have/take the time to order a bit, so it turns into a majority
 vote.

Or there are many people like me who won’t vote at all because the process is 
so difficult and time-consuming. :-( 

 That said, you're absolutely right the visual feedback of the voting
 system is suboptimal.  I'd be very interested in seeing a good UI for
 this sort of task.  I imagine it'd be pretty close to printing
 everything on small pieces of paper and ordering them by hand ;) 

A good UI is what we need here. Maybe someone can write a simple app that does 
the following:

* download the logos from the Haskell web server

* present the user pairs of logos and let him decide which one of the two
presented logos he likes better

* shows a progress bar during voting

* presents the voting result for easy entering into the webpage

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


Re: [Haskell-cafe] Re: Haskell Logo Voting has started!

2009-03-18 Thread Wolfgang Jeltsch
Am Mittwoch, 18. März 2009 10:03 schrieb Benjamin L.Russell:
 Just go through the list, choose your top favorite, and assign rank 1
 to it;

Is rank 1 the best or the worst?

I thought it would be the worst so I would probably have voted exactly the 
opposite way than I wanted to. :-( 

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


Re: [Haskell-cafe] Re: Query on list comprehension

2009-03-18 Thread Yitzchak Gale
Melanie_Green writes:
 I want to use listcomprehension to output the pattern below...

Jón Fairbairn wrote:
 Why do you want to use list comprehensions?
 What if they aren't the best way of getting the
 result you want?

unlines . tail . inits . repeat $ 'a'

 concat [replicate n 'a' ++ \n | n - [1..]]

Or:

unlines [replicate n 'a' | n - [1..]]

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


Re: [Haskell-cafe] Re: Haskell Logo Voting has started!

2009-03-18 Thread Wolfgang Jeltsch
Am Dienstag, 17. März 2009 21:08 schrieb Robin Green:
 However, I am now hacking together a quick-and-dirty utility for
 ranking things which I will put on hackage. I'm not sure that anyone
 other than myself will use it, but it's fun hacking it up.

If you announce it on the mailing list, I might use it.

By the way, when will the voting period be over?

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


[Haskell-cafe] Memoizing partially evaluated computations.

2009-03-18 Thread Sebastiaan Visser
Suppose I have a list of IO computations that depends on a few very  
time consuming pure operations. The pure operations are not dependent  
on the real world:


  computation :: [IO Int]
  computation = [
  smallIOfunc timeConsumingPureOperation0
, smallIOfunc timeConsumingPureOperation1
, smallIOfunc timeConsumingPureOperation2
, smallIOfunc timeConsumingPureOperation3
]
where smallIOfunc a = print a  return a

In my main function I would like to repeatedly print the values

  main = forever $
sequence_ (map (=print) computation)

When I do this, all the time consuming operations will be reevaluated  
every run of the main loop. Is there a any (simple or smart) way to  
prevent the garbage collector from cleaning up the fully evaluated  
thunks inside my computation? As if it were something like this:


  computation :: [IO Int]
  computation = [smallIOfunc 42, smallIOfunc 34385, smallIOfunc 3,  
smallIOfunc 55]


Of course I could plugin some kind of Int memoizer inside my  
computation, but I do not really have the control to change things  
`deep' inside the code. I want to have some form of snapshot of a list  
of partially evaluated IO computations...


Any suggestions?

Tanks,
Sebastiaan

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


Re: [Haskell-cafe] Memoizing partially evaluated computations.

2009-03-18 Thread minh thu
2009/3/18 Sebastiaan Visser sfvis...@cs.uu.nl:
 Suppose I have a list of IO computations that depends on a few very time
 consuming pure operations. The pure operations are not dependent on the real
 world:

  computation :: [IO Int]
  computation = [
  smallIOfunc timeConsumingPureOperation0
, smallIOfunc timeConsumingPureOperation1
, smallIOfunc timeConsumingPureOperation2
, smallIOfunc timeConsumingPureOperation3
]
where smallIOfunc a = print a  return a

 In my main function I would like to repeatedly print the values

  main = forever $
sequence_ (map (=print) computation)

 When I do this, all the time consuming operations will be reevaluated every
 run of the main loop. Is there a any (simple or smart) way to prevent the
 garbage collector from cleaning up the fully evaluated thunks inside my
 computation? As if it were something like this:

  computation :: [IO Int]
  computation = [smallIOfunc 42, smallIOfunc 34385, smallIOfunc 3,
 smallIOfunc 55]

 Of course I could plugin some kind of Int memoizer inside my computation,
 but I do not really have the control to change things `deep' inside the
 code. I want to have some form of snapshot of a list of partially evaluated
 IO computations...

 Any suggestions?

Hi,

If timeConsumingPureOperation is pure, the problem is thus not related to IO,
and your question remains the same : how to memoize timeConsumingPureOperation
for some arguments. Since you want to repeatidly call main, it seems a good idea
to wrap your pure operation in a memoizing CAF (and give the wrapped version to
smalIOFuncf).

You can here : http://www.haskell.org/haskellwiki/Memoization

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


Re: [Haskell-cafe] encoding for least fixpoint

2009-03-18 Thread Ryan Ingram
One typo correction:

On Wed, Mar 18, 2009 at 2:15 AM, Ryan Ingram ryani.s...@gmail.com wrote:
 Let Pair a b be an abbreviation for forall c. (a - b - c),

This should say that Pair a b is an abbreviation for
   forall c. (a - b - c) - c

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


Re: [Haskell-cafe] Memoizing partially evaluated computations.

2009-03-18 Thread Sebastiaan Visser

On Mar 18, 2009, at 12:06 PM, minh thu wrote:


2009/3/18 Sebastiaan Visser sfvis...@cs.uu.nl:
Suppose I have a list of IO computations that depends on a few very  
time
consuming pure operations. The pure operations are not dependent on  
the real

world:


computation :: [IO Int]
computation = [
smallIOfunc timeConsumingPureOperation0
  , smallIOfunc timeConsumingPureOperation1
  , smallIOfunc timeConsumingPureOperation2
  , smallIOfunc timeConsumingPureOperation3
  ]
  where smallIOfunc a = print a  return a


In my main function I would like to repeatedly print the values


main = forever $
  sequence_ (map (=print) computation)


When I do this, all the time consuming operations will be  
reevaluated every
run of the main loop. Is there a any (simple or smart) way to  
prevent the
garbage collector from cleaning up the fully evaluated thunks  
inside my

computation? As if it were something like this:


computation :: [IO Int]
computation = [smallIOfunc 42, smallIOfunc 34385, smallIOfunc 3,
smallIOfunc 55]


Of course I could plugin some kind of Int memoizer inside my  
computation,
but I do not really have the control to change things `deep' inside  
the
code. I want to have some form of snapshot of a list of partially  
evaluated

IO computations...

Any suggestions?


Hi,

If timeConsumingPureOperation is pure, the problem is thus not  
related to IO,
and your question remains the same : how to memoize  
timeConsumingPureOperation
for some arguments. Since you want to repeatidly call main, it seems  
a good idea
to wrap your pure operation in a memoizing CAF (and give the wrapped  
version to

smalIOFuncf).


The problem is that the `timeConsumingPureOperation' is somewhere very  
deep inside my code at a point I cannot alter. Like this:


 -- This I can change:
 myIOCode = forever (deepLibraryCode = print)

 -- This I cannot change:
 deepLibraryCode :: IO Int
 deepLibraryCode = makeIOfunctionFrom timeConsumingPureOperation

The separation between the make `makeIOfunctionFrom' and  
`timeConsumingPureOperation' might not even be that clear as in my  
example.


That is why I am looking for some high level way of memoizing.


You can here : http://www.haskell.org/haskellwiki/Memoization

HTH,
Thu


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


Re: [Haskell-cafe] encoding for least fixpoint

2009-03-18 Thread Wouter Swierstra

Hi Ben,

But this definition coincides with his definition of the greatest  
fixpoint


In Haskell the least and greatest fixed points coincide.  
(Categorically, this is called algebraically compact I think). You  
can still fake coinductive types to some degree by consistently  
using unfolds rather than folds.



Then I stumbled over a blog entry of Shin-Cheng Mu [2] and from there
over an article of Wadler [3], where the least fixpoint is encoded as

Lfix X. F X  =  All X. (F X - X) - X.

and the greatest fixpoint as

Gfix X. F X  =  Exists X. (X - F X) * X.

I would like to understand these definitions, or get an intuition  
about

their meaning.


So here's my attempt at an explanation.

For every least fixed point of a functor:

data Mu f = In (f (Mu f))

you can define a fold:

fold :: forall a . (f a - a) - Mu f - a
fold algebra (In t) = algebra (fmap (fold algebra) t)

Now your definition of Lfix above basically identifies the data type  
with all possible folds over it. (I suspect you will need some  
parametricity result to show that this is really an isomorphism)


For codata, instead of having a fold you get an unfold:

unfold :: forall a . (a - f a) - a - Nu f
unfold coalg x = In (fmap (unfold coalg) (g x))

And your Gfix type above identifies every codata type with its unfold.  
To see this, you need to realise that:


forall a . (a - f a) - a - Nu f

is isomorphic to:

forall a . (a - f a , a) - Nu f

is isomporphic to:

(exists a . (a - f a, a)) - Nu f

which gives you one direction of the iso.

Now in case you think this is all airy-fairy category theory, there's  
a really nice paper Stream fusion: from lists to streams to nothing  
at all that shows how to use this technology to get some serious  
speedups over all kinds of list-processing functions.


Hope this helps,

  Wouter



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


Re: [Haskell-cafe] Re: Haskell Logo Voting has started!

2009-03-18 Thread Wolfgang Jeltsch
Am Mittwoch, 18. März 2009 03:22 schrieb Robin Green:
 I'm afraid it is entirely terminal-based (i.e. text only), so it doesn't
 show the pictures.

Hmm, this doesn’t help me since I’ve already written a terminal-based app. See 
attachement. However, no guarantees that this app works as intended. The 
preferences shown by the app are currently meant to stand for better logos if 
they are lower. So 1 is the winner, not 113.

Well, the terminal-based app is still not enough for me since it’s way too 
time-consuming to always lookup the pictures. You should have a GUI showing 
the pictures and allowing you to select the better one of a pair by a single 
click.

Best wishes,
Wolfgang
module Main (

main

) where

import List hiding (sort)

main :: IO ()
main = do
   putStr Number of items: 
   itemCount - fmap read getLine
   sorted - sort (\val1 val2 - do
 putStr $ Is++
  show val1   ++
   better than  ++
  show val2   ++
  ? 
 initAnswer - getLine
 getDecision initAnswer)
  [1..itemCount]
   putStr $ unlines [show val ++  has preference  ++ show rank |
 (val,rank) - sortBy (\(val1,rank1)
(val2,rank2) - compare 
val1 val2) $
   zip sorted [1..itemCount]]

getDecision :: String - IO Bool
getDecision n = return False
getDecision y = return True
getDecision _   = do
  putStr Illegal answer. Try again. 
  answer - getLine
  getDecision answer

sort :: (Monad monad) = (val - val - monad Bool) - [val] - monad [val]
sort compare []= return []
sort compare [val] = return [val]
sort compare vals  = let

 (part1,part2) = dissociate vals

 in do
sorted1 - sort compare part1
sorted2 - sort compare part2
merge compare sorted1 sorted2

dissociate :: [val] - ([val],[val])
dissociate []   = ([],[])
dissociate [val]= ([val],[])
dissociate (val1 : val2 : vals) = let

  (subpart1,subpart2) = dissociate vals

  in (val1 : subpart1,val2 : subpart2)

merge :: (Monad monad) = (val - val - monad Bool) - [val] - [val] - 
monad [val]
merge compare [] [] = return []
merge compare vals1  [] = return vals1
merge compare [] vals2  = return vals2
merge compare (val1 : vals1) (val2 : vals2) = do
  before - compare val1 
val2
  if before
  then do
   subresult - 
merge compare

  vals1

  (val2 : vals2)
   return (val1 
: subresult)
  else do
   subresult - 
merge compare

  (val1 : vals1)

  vals2
   return (val2 
: subresult)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Haskell Logo Voting has started!

2009-03-18 Thread Robin Green
Firstly, apologies to everyone for sending the same message to the list
five times, yesterday! The mailserver I use kept timing out, and I had
thought that my mail client would handle attempts to resend an email
appropriately, but apparently not. Time to put a paper bag over my head!

On Wed, 18 Mar 2009 11:43:26 +0100
Wolfgang Jeltsch g9ks1...@acme.softbase.org wrote:

 If you announce it on the mailing list, I might use it.

I'm afraid it is entirely terminal-based (i.e. text only), so it doesn't
show the pictures. Someone could try and convert it into a web app and
display the pictures, but I have no plans to do that.

It is not working at the moment, but I hope to get it working and
announce it later this week.
 
 By the way, when will the voting period be over?

The polling page says The poll ends March 24, 2009 at 12:00 UTC.
-- 
Robin
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Need an overview of FP-related research topics

2009-03-18 Thread Yitzchak Gale
I wrote:
 I would like some links that would give such a person
 a nice overview of the various active areas of
 FP-related research these days...

Bernie Pope wrote:
 Some ideas off the top of my head...

Thanks, that's exactly what I was looking for.
Also, thanks to Sean for suggesting the History paper.
I sent it on, hope it does the trick :)

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


[Haskell-cafe] Proof of duality theorem of fold?

2009-03-18 Thread R J

I'm trying to prove the following duality theorem of fold for finite lists:

   foldr f e xs =  foldl (flip f) e (reverse xs)

where

   reverse  :: [a] - [a]
  
reverse []   =  []
  
reverse (x:xs)   =  reverse xs ++ [x]

   flip :: (a - b - c) - b - a - c
   flip f y x   =  f x y

   foldr:: (a - b - b) - b - [a] - b
   foldr f e [] =  e
   foldr f e (x : xs)   =  f x (foldr f e xs)

   foldl:: (b - a - b) - b - [a] - b
   foldl f e [] =  e
   foldl f e (x : xs)   =  foldl f (f e x) xs


I'm stuck on the induction case.  Can someone help?  Here's what I've got so 
far:

Proof:

   Case _|_.

  Left-side reduction:

 foldr f e _|_
  =  {case exhaustion of foldr}
 _|_

  Right-side reduction:

 foldl (flip f) e (reverse _|_)
  =  {case exhaustion of reverse}
 foldl (flip f) e _|_
  =  {case exhaustion of foldl}
 _|_

   Case [].

  Left-side reduction:

 foldr f e []
  =  {first equation of foldr}
 e

  Right-side reduction:

 foldl (flip f) e (reverse [])
  =  {first equation of reverse}
 foldl (flip f) e []
  =  {first equation of foldl}
 e

   Case (x : xs).

  Left-side reduction:

 foldr f e (x : xs)
  =  {second equation of foldr}
 f x (foldr f e xs)
  =  {induction hypothesis: foldr f e xs = foldl (flip f) e (reverse xs)}
 f x (foldl (flip f) e (reverse xs))

  Right-side reduction:

 foldl (flip f) e (reverse (x : xs))
  =  {second equation of reverse}
 foldl (flip f) e (reverse xs ++ [x])
_
Hotmail® is up to 70% faster. Now good news travels really fast. 
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Proof of duality theorem of fold?

2009-03-18 Thread Daniel Fischer
Am Mittwoch, 18. März 2009 12:57 schrieb R J:
 I'm trying to prove the following duality theorem of fold for finite lists:

foldr f e xs =  foldl (flip f) e (reverse xs)

 where

reverse  :: [a] - [a]

 reverse []   =  []

 reverse (x:xs)   =  reverse xs ++ [x]

flip :: (a - b - c) - b - a - c
flip f y x   =  f x y

foldr:: (a - b - b) - b - [a] - b
foldr f e [] =  e
foldr f e (x : xs)   =  f x (foldr f e xs)

foldl:: (b - a - b) - b - [a] - b
foldl f e [] =  e
foldl f e (x : xs)   =  foldl f (f e x) xs


 I'm stuck on the induction case.  Can someone help?  Here's what I've got
 so far:

 Proof:

Case _|_.

   Left-side reduction:

  foldr f e _|_
   =  {case exhaustion of foldr}
  _|_

   Right-side reduction:

  foldl (flip f) e (reverse _|_)
   =  {case exhaustion of reverse}
  foldl (flip f) e _|_
   =  {case exhaustion of foldl}
  _|_

Case [].

   Left-side reduction:

  foldr f e []
   =  {first equation of foldr}
  e

   Right-side reduction:

  foldl (flip f) e (reverse [])
   =  {first equation of reverse}
  foldl (flip f) e []
   =  {first equation of foldl}
  e

Case (x : xs).

   Left-side reduction:

  foldr f e (x : xs)
   =  {second equation of foldr}
  f x (foldr f e xs)
   =  {induction hypothesis: foldr f e xs = foldl (flip f) e (reverse
 xs)} f x (foldl (flip f) e (reverse xs))

= (flip f) (foldl (flip f) e (reverse xs)) x


   Right-side reduction:

  foldl (flip f) e (reverse (x : xs))
   =  {second equation of reverse}
  foldl (flip f) e (reverse xs ++ [x])

Now prove the

Lemma:

foldl g e (ys ++ zs) = foldl g (foldl g e ys) zs

for all g, e, ys and zs of interest.
(I don't see immediately under which conditions this identity could break, 
maybe there aren't any)

Then the last line of the right hand side reduction can be rewritten as the 
new last of the left.

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


Re: [Haskell-cafe] Who generates Haskell code and uses type information at runtime? (fwd)

2009-03-18 Thread Chris Brown
I'm not sure if you got my previous message, as I was having some 
problems posting to the list...



Putting in a nutshell, I generalize an extensional defined function
definition into a recursive one. This is done in a number of steps by
modifying expressions and exploiting type information of
sub-expressions. For example:

rev [] = []
rev [a] = [a]
rev [a,b] = [b,a]
rev [a,b,c] = [c,b,a]

~~

rev x = y

~~

rev [] = []
rev (x:xs) = (y:ys)

~~

rev [] = []
rev (x:xs) = (last (x:xs)) : (reverse (x:xs))


The initial set of rules is given by the user (in a file, via IO, ...).
The problem later is to infer the type of an intermediate variable, e.g.
'y'.


I'm still not entirely sure what you want to do here. But it sounds like HaRe 
could already do most of this for you via a sequence of folds, unfolds, 
introduce pattern matching and generative folding. HaRe already has 
built-in support for some symbolic evaluation, which is already used in the generative

fold refactoring, and has type checking support too.

http://www.cs.kent.ac.uk/projects/refactor-fp/hare.html

If it doesn't do exactly what you want out of the tin, it does have a large API 
for designing transformations over Haskell code.


http://www.cs.kent.ac.uk/projects/refactor-fp/hare/haddock/RefacUtils.html



Chris.






Thanks,

Martin

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



--
Chris Brown

Visualization Software Engineer, Peiriannydd Meddalwedd Delweddu.

Cast Ltd., Technium CAST,
Ffordd Penlan, Parc Menai,
Bangor, Gwynedd UK. LL57 4HJ.

Tel: +44 (0)1248 675038
Fax: +44 (0)1248 675012
Mobile: +44 (0)7917 763712


--
Centre for Advanced Software Technology Limited is a limited company registered 
in England and Wales.
Registered Number: 04473521, Registered Office: Finance Office, Bangor 
University, College Road, Bangor, Gwynedd. LL57 2DG.

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


Re: [Haskell-cafe] Proof of duality theorem of fold?

2009-03-18 Thread Daniel Fischer
Am Mittwoch, 18. März 2009 13:10 schrieb Daniel Fischer:
 Now prove the

 Lemma:

 foldl g e (ys ++ zs) = foldl g (foldl g e ys) zs

 for all g, e, ys and zs of interest.
 (I don't see immediately under which conditions this identity could break,
 maybe there aren't any)

Of course, hit send and you immediately think of

foldl (flip const) whatever (undefined ++ [1,2,3])
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Proof of duality theorem of fold?

2009-03-18 Thread MigMit

More interesting:

foldl (flip const) whatever (repeat 1 ++ [1,2,3])

Daniel Fischer wrote on 18.03.2009 15:17:

Am Mittwoch, 18. März 2009 13:10 schrieb Daniel Fischer:

Now prove the

Lemma:

foldl g e (ys ++ zs) = foldl g (foldl g e ys) zs

for all g, e, ys and zs of interest.
(I don't see immediately under which conditions this identity could break,
maybe there aren't any)


Of course, hit send and you immediately think of

foldl (flip const) whatever (undefined ++ [1,2,3])
___
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] ANN: regex-tdfa-1.1.0

2009-03-18 Thread ChrisK
I have just uploaded the new regex-tdfa-1.1.0 to hackage.  This version is a 
small performance update to the old regex-tdfa-1.0.0 version.


Previously all text (e.g. ByteString) being search was converted to String and 
sent through a single engine.


The new version uses a type class and SPECIALIZE pragmas to avoid converting to 
String.  This should make adding support for searching other Char containers 
easy to do.


The new version includes six specialized engine loops to take advantage of 
obvious optimizations of the traversal.  The previous version had only a couple 
of such engines.  The new code paths have been tested for correctness and no 
performance degradations have shown up.


--
Chris

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


[Haskell-cafe] Re: categories and monoids

2009-03-18 Thread Chung-chieh Shan
Wolfgang Jeltsch g9ks1...@acme.softbase.org wrote in article 
200903181116.37073.g9ks1...@acme.softbase.org in gmane.comp.lang.haskell.cafe:
 Am Dienstag, 17. März 2009 18:43 schrieben Sie:
  There's no such implication in English. The standard example used by
  linguists is fake gun.
 Okay, but this is a corner case isn???t it?

Perhaps (depending on what you consider to be a corner case).
But then why not take generalized monoid to be a corner case too?

 And the phrase ???generalized monoid??? has another problem. It???s not a 
 single 
 monoid that is generalized but the ???monoid concept???. The class of monoids 
 is 
 extended to become the class of categories.

I'm not sure what problem you mean.  Perhaps you have in mind a
grammar that defines what strings are well-formed English sentences
and a semantics that specifies their denotations (say, their truth
conditions), such that it turns out that the meaning of generalized
monoid is inappropriate.  But what do you have in mind?

Linguists typically take adjectives to denote functions from noun
meanings to noun meanings.  Because linguists also typically take nouns
to denote functions, adjectives end up denoting higher-order functions.
That's why this message is still generalized on-topic. :)

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
Who would have thought LISP would come back to life.
Steve Bourne, in an interview about Bourne Shell.

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


[Haskell-cafe] Re: Memoizing partially evaluated computations.

2009-03-18 Thread Chung-chieh Shan
Sebastiaan Visser sfvis...@cs.uu.nl wrote in article 
d86a7d11-f95f-4a27-a13c-2d78afda2...@cs.uu.nl in gmane.comp.lang.haskell.cafe:
 Suppose I have a list of IO computations that depends on a few very  
 time consuming pure operations. The pure operations are not dependent  
 on the real world:
 
computation :: [IO Int]
computation = [
smallIOfunc timeConsumingPureOperation0
  , smallIOfunc timeConsumingPureOperation1
  , smallIOfunc timeConsumingPureOperation2
  , smallIOfunc timeConsumingPureOperation3
  ]
  where smallIOfunc a = print a  return a

I take it that, because you do not really have the control to change
things `deep' inside the code, it is not an option to redefine

computation = [
smallIOfunc x0
  , smallIOfunc x1
  , smallIOfunc x2
  , smallIOfunc x3
  ]
  where smallIOfunc a = print a  return a
x0 = timeConsumingPureOperation0
x1 = timeConsumingPureOperation1
x2 = timeConsumingPureOperation2
x3 = timeConsumingPureOperation3

Can you define smallIOfunc to be more polymorphic in the monad?  That
is, can you define a class of monads (MonadBehavior, let's call it)
that contains member functions for operations (such as print) you want
to perform in smallIOfunc, then write smallIOfunc to be polymorphic
over such a monad?  If so, you can then implement two instances of this
class: one for IO and one for a term representation of behavior.

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
Who would have thought LISP would come back to life.
Steve Bourne, in an interview about Bourne Shell.

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


Re: [Haskell-cafe] .hi inconsistency bug.

2009-03-18 Thread Daniel Gorín
So, if I understand correctly, the interpreter is compiling  
MainTypes twice?


No, the interpreter is trying to compile types that were already  
compiled by the compiler when building your application. The resulting  
types are incompatible.


Could this be a result of having two outputs (one executable and one  
library) in my .cabal file? it _does_ compile those things twice...  
If I create a second cabal file which separates these two different  
packages, would that fix it?


I don't think so. If you already have your application split in  
library part + executable part, then everything should be fine (as  
long as the library is installed before running your application).


The issue is, the (dynamic) interpreter part of my code is part of  
the main loop of the program, and is (as far as I can see)  
inseparable from the rest of the code.


What you need to separate is the code you are planning to interpret in  
runtime. For example, say you have:


src/HackMail/Main.hs
src/HackMail/Data/Types.hs
src/SomePlugin.hs

and SomePlugin.hs is loaded by the interpreter, then you may want to  
reorganize your files like

this:

src/HackMail/Main.hs
src/HackMail/Data/Types.hs
plugins/SomePlugin.hs

and set the source path to plugins directory (using something like  
unsafeSetGhcOption -i./plugins, or set [searchPath := [./ 
plugins]], if using the darcs version).


Daniel

I'll give the cabal thing a try, given the incredible triviality of  
doing everything with cabal, I should be done testing the solution  
before I hit the send button... Cabal guys, you rock.


Thanks again, Dan.

/Joe

Daniel Gorín wrote:

Hi

Just a wild guess but maybe the interpreter is recompiling (in  
runtime) code that has already been compiled to build your  
application (in compile-time). This may lead to inconsistencies  
since a type such as HackMail.Data.Main.Types.Filter may refer to  
two different (and incompatible) types.


To see if this is the case, make sure your dynamic code is not  
located together with your base code (i.e., move it to another  
directory, and set the src file directory for the interpreter  
accordingly). Now you may get another runtime error, something  
along the lines of Module not found: HackMail.Data.MainTypes.  
This basically means that you need to make your (already compiled)  
types available to the interpreter. I think the simplest way is to  
put all your support types in a package, register it with ghc, link  
your application to it, and ask the interpreter to use this package  
(with a -package  flag).


Hope this helps!

Daniel

On Mar 17, 2009, at 11:52 PM, Joe Fredette wrote:


List,

I've got this project, source on patch-tag here[1]

It's a nice little project, I've got the whole thing roughly  
working, it compiles okay, everything seems to work, until I try  
to run it, specifically when I run it in ghci, or when I run the  
main executable (which uses hint), and look at any type involving  
my Email type, it gives me the following error:


Type syonym HackMail.Data.MainTypes.Filter:
  Can't find interface-file declaration for type constructor or  
class HackMail.Data.ParseEmail.Email

Probable cause: bug in .hi-boot file, or inconsistent .hi file
Use -ddump-if-trace to get an idea of which file caused the  
error


As far as I understand, it wants to find the interface-file  
declaration for a specific type (Email) exported by the ParseEmail  
module, all of the exports (I think) are in order. I've tried  
mucking around with it a bit, but I don't fully understand what  
the error even means, much less how to fix it.


Other relevant info, Email is exported in a roundabout way, namely  
by importing a module MainTypes, which exports a module Email,  
which exports a the ParseEmail Module, which exports the datatype  
Email.


The Filter delcaration it _actually_ complains about (it's just  
the first place the email type is invoked) is:


type Filter a = ReaderT (Config, Email) IO a

nothing particularly special.

Any help fixing this is greatly appreciated, I did find this bug  
report[2] which seems like it might be relevant.


But trying to unregister - cabal clean - cabal install doesn't  
fix it. I've also tried manually removing the dist/ folder, and  
also unregistering the package.


Thanks again.

/Joe

[1] http://patch-tag.com/repo/Hackmail/browse
[2] http://hackage.haskell.org/trac/ghc/ticket/2057
jfredett.vcf___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




jfredett.vcf


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


Re: [Haskell-cafe] Proof of duality theorem of fold?

2009-03-18 Thread Daniel Fischer
Am Mittwoch, 18. März 2009 12:57 schrieb R J:
 I'm trying to prove the following duality theorem of fold for finite lists:

foldr f e xs =  foldl (flip f) e (reverse xs)

Better make that skeleton-defined finite lists:

Prelude foldr (++) [] (this: goes: so: far:undefined)
this goes so far*** Exception: Prelude.undefined
Prelude foldl (flip (++)) [] (reverse (this: goes: so: 
far:undefined))
*** Exception: Prelude.undefined



 where

reverse  :: [a] - [a]

 reverse []   =  []

 reverse (x:xs)   =  reverse xs ++ [x]

flip :: (a - b - c) - b - a - c
flip f y x   =  f x y

foldr:: (a - b - b) - b - [a] - b
foldr f e [] =  e
foldr f e (x : xs)   =  f x (foldr f e xs)

foldl:: (b - a - b) - b - [a] - b
foldl f e [] =  e
foldl f e (x : xs)   =  foldl f (f e x) xs


 I'm stuck on the induction case.  Can someone help?  Here's what I've got
 so far:

 Proof:

Case _|_.

   Left-side reduction:

  foldr f e _|_
   =  {case exhaustion of foldr}
  _|_

   Right-side reduction:

  foldl (flip f) e (reverse _|_)
   =  {case exhaustion of reverse}
  foldl (flip f) e _|_
   =  {case exhaustion of foldl}
  _|_

Case [].

   Left-side reduction:

  foldr f e []
   =  {first equation of foldr}
  e

   Right-side reduction:

  foldl (flip f) e (reverse [])
   =  {first equation of reverse}
  foldl (flip f) e []
   =  {first equation of foldl}
  e

Case (x : xs).

   Left-side reduction:

  foldr f e (x : xs)
   =  {second equation of foldr}
  f x (foldr f e xs)
   =  {induction hypothesis: foldr f e xs = foldl (flip f) e (reverse
 xs)} f x (foldl (flip f) e (reverse xs))

   Right-side reduction:

  foldl (flip f) e (reverse (x : xs))
   =  {second equation of reverse}
  foldl (flip f) e (reverse xs ++ [x])
 _
 Hotmail® is up to 70% faster. Now good news travels really fast.
 http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009

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


Re: [Haskell-cafe] Re: Query on list comprehension

2009-03-18 Thread Kalman Noel
Jon Fairbairn schrieb:
 Melanie_Green jac_legend_...@hotmail.com writes:
 What are the limitations of list comprehension. [...]
 a
 aa
 aaa
 
 I'm not clear what you mean by the question. Why do you want
 to use list comprehensions? What if they aren't the best way
 of getting the result you want?
 
 You can write 
 
 [a | b - [replicate n 'a' | n - [1..]], a - b ++ \n] 
 
 but does that replicate fail to meet your specification?

Since we're »holfing« again:

fix $ \xs - [ 'a':xs | xs - []:xs ]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: categories and monoids

2009-03-18 Thread Kalman Noel
Wolfgang Jeltsch schrieb:
 Okay. Well, a monoid with many objects isn’t a monoid anymore since a monoid 
 has only one object. It’s the same as with: “A ring is a field whose 
 multiplication has no inverse.” One usually knows what is meant with this but 
 it’s actually wrong. Wrong for two reasons: First, because the multiplication 
 of a field has an inverse. Second, because the multiplication of a ring is 
 not forced to have no inverse but may have one.

“A ring is like a field, but without a multiplicative inverse” is, in my
eyes, an acceptable formulation. We just have to agree that “without”
here refers to the definition, rather than to the definitum.


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


Re: [Haskell-cafe] Re: categories and monoids

2009-03-18 Thread Conal Elliott
So a clearer reframing might be: “Ring is like Field, but without
multiplicative inverse”.

On Wed, Mar 18, 2009 at 7:17 AM, Kalman Noel noel.kal...@googlemail.comwrote:

 Wolfgang Jeltsch schrieb:
  Okay. Well, a monoid with many objects isn’t a monoid anymore since a
 monoid
  has only one object. It’s the same as with: “A ring is a field whose
  multiplication has no inverse.” One usually knows what is meant with this
 but
  it’s actually wrong. Wrong for two reasons: First, because the
 multiplication
  of a field has an inverse. Second, because the multiplication of a ring
 is
  not forced to have no inverse but may have one.

 “A ring is like a field, but without a multiplicative inverse” is, in my
 eyes, an acceptable formulation. We just have to agree that “without”
 here refers to the definition, rather than to the definitum.


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


Re: [Haskell-cafe] Type equality proof

2009-03-18 Thread Conal Elliott
I use these defs:

-- | Lift proof through a unary type constructor
liftEq :: a :=: a' - f a :=: f a'
liftEq Refl = Refl

-- | Lift proof through a binary type constructor (including '(,)')
liftEq2 :: a :=: a' - b :=: b' - f a b :=: f a' b'
liftEq2 Refl Refl = Refl

-- | Lift proof through a ternary type constructor (including '(,,)')
liftEq3 :: a :=: a' - b :=: b' - c :=: c' - f a b c :=: f a' b' c'
liftEq3 Refl Refl Refl = Refl

etc.



On Tue, Mar 17, 2009 at 3:39 AM, Martijn van Steenbergen 
mart...@van.steenbergen.nl wrote:

 Olá café,

 With the recent generic programming work and influences from type-dependent
 languages such as Agda, the following data type seems to come up often:

  data (a :=: a') where
  Refl :: a :=: a


 Everyone who needs it writes their own version; I'd like to compile a
 package with this data type and related utilities, if such a package doesn't
 exist already (I couldn't find one). Below is what I have so far; I'd much
 appreciate it if you added your ideas of what else the package should
 contain.

  {-# LANGUAGE GADTs #-}
 {-# LANGUAGE TypeOperators #-}

 module Eq where

 data (a :=: a') where
  Refl :: a :=: a

 class Eq1 f where
  eq1 :: f a - f a' - Maybe (a :=: a')

 class Eq2 f where
  eq2 :: f a b - f a' b' - Maybe (a :=: a', b :=: b')

 class Eq3 f where
  eq3 :: f a b c - f a' b' c' - Maybe (a :=: a', b :=: b', c :=: c')


 Thank you,

 Martijn.
 ___
 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] encoding for least fixpoint

2009-03-18 Thread David Menendez
On Wed, Mar 18, 2009 at 5:15 AM, Ryan Ingram ryani.s...@gmail.com wrote:
 newtype Lfix f = Lfix (forall x. (f x - x) - x)

 l_in :: Functor f = f (Lfix f) - Lfix f
 l_in fl = Lfix (\k - k (fmap (\(Lfix j) - j k) fl))
 -- derivation of l_in was complicated!

I found l_in easiest to write in terms of cata and build.

cata :: (f a - a) - Lfix f - a
cata f (Lfix t) = f t

build :: (forall x. (f x - x) - c - x) - c - Lfix f
build t c = Lfix (\f - t f c)

l_in :: Functor f = f (Lfix f) - Lfix f
l_in = build (\f - f . fmap (cata f))

And, dually,

ana :: (a - f a) - a - Gfix f
ana f a = Gfix f a

destroy :: (forall x. (x - f x) - x - c) - Gfix f - c
destroy t (Gfix f x) = t f x

g_out :: Functor f = Gfix f - f (Gfix f)
g_out = destroy (\f - fmap (ana f) . f)

 There's something from Wadler's draft that doesn't make sense to me.  He says:

 This introduces a new type, T = Lfix X. F X, satisfying the isomorphism
 T ~ F T.  Note that it is an isomorphism, not an equality:  the type
 comes equipped with functions in : T - F T and out : F T - T.

 While I was able to derive in for Lfix, and out for Gfix, I don't
 think it's possible to derive a generic out for Lfix or in for
 Gfix; maybe such a function *can* always be generated (specific to a
 particular type), but I don't think it's possible to do so while just
 relying on Functor.  Perhaps stronger generic programming methods are
 necessary.

l_out :: Functor f = Lfix f - f (Lfix f)
l_out = cata (fmap l_in)

g_in :: Functor f = f (Gfix f) - Gfix f
g_in = ana (fmap g_out)

-- 
Dave Menendez d...@zednenem.com
http://www.eyrie.org/~zednenem/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Type equality proof

2009-03-18 Thread Conor McBride

Hi

On 18 Mar 2009, at 15:00, Conal Elliott wrote:


I use these defs:

-- | Lift proof through a unary type constructor
liftEq :: a :=: a' - f a :=: f a'
liftEq Refl = Refl

-- | Lift proof through a binary type constructor (including '(,)')
liftEq2 :: a :=: a' - b :=: b' - f a b :=: f a' b'
liftEq2 Refl Refl = Refl

-- | Lift proof through a ternary type constructor (including '(,,)')
liftEq3 :: a :=: a' - b :=: b' - c :=: c' - f a b c :=: f a' b' c'
liftEq3 Refl Refl Refl = Refl


Makes you want kind polymorphism, doesn't it?
Then we could just have

  (=$=) :: f :=: g - a :=: b - f a :=: g b

Maybe the liftEq_n's are the way to go (although
we called them resp_n when I was young), but
they don't work for higher kinds.

An alternative ghastly hack might be

 data PackT2T (f :: * - *)

 (=$=) :: (PackT2T f :=: PackT2T g) -
  (a :=: b) - (f a :=: g b)
 Refl =$= Refl = Refl

But now you need a packer and an application for
each higher kind. Or some bonkers type-level
programming.

This one will run and run...

Cheers

Conor

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


[Haskell-cafe] Re: Type equality proof

2009-03-18 Thread Ashley Yakeley

Martijn van Steenbergen wrote:

Olá café,

With the recent generic programming work and influences from 
type-dependent languages such as Agda, the following data type seems to 
come up often:



data (a :=: a') where
  Refl :: a :=: a


Everyone who needs it writes their own version; I'd like to compile a 
package with this data type and related utilities, if such a package 
doesn't exist already (I couldn't find one). Below is what I have so 
far; I'd much appreciate it if you added your ideas of what else the 
package should contain.


Have a look at these:

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

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


Re: [Haskell-cafe] encoding for least fixpoint

2009-03-18 Thread Ryan Ingram
On Wed, Mar 18, 2009 at 8:10 AM, David Menendez d...@zednenem.com wrote:
 l_out :: Functor f = Lfix f - f (Lfix f)
 l_out = cata (fmap l_in)

 g_in :: Functor f = f (Gfix f) - Gfix f
 g_in = ana (fmap g_out)

Well, you just blew my mind.  I had an informal proof in my head of
why g_in shouldn't be possible to write, but I must be missing
something huge.

Looks like I need to get out some paper and reduce this by hand,
because there is some black magic going on here :)

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


Re: [Haskell-cafe] OpenGL and Cabal installation

2009-03-18 Thread Henk-Jan van Tuyl
On Wed, 18 Mar 2009 04:34:29 +0100, Mark Spezzano  
mark.spezz...@chariot.net.au wrote:




configure: error: no GLUT header found, so this package cannot be built

See `config.log' for more details.


Where is it looking for these glut.h files? I’ve tried putting them
everywhere in my PATH but msys won’t find them.


Add an environment variable C_INCLUDE_PATH and assign it the value of the  
directory where you keep the header files; for instance, if the glut.h  
file is in:

  C:\usr\local\include\GLUT
then do
  Set C_INCLUDE_PATH=C:\usr\local\include
before compiling, or set this variable in Windows with System properties.
Similarly, set LIBRARY_PATH for the libraries to link.

--
Regards,
Henk-Jan van Tuyl


--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--


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


Re: [Haskell-cafe] encoding for least fixpoint

2009-03-18 Thread Benedikt Ahrens
Thanks a lot to all of you for your help.

It took some time for me to realize that the only difference between
Vene and Wadler is in fact, that Wadler has an explicit representation
for the fixpoints - which answers the question of existence.

I will spend some more time on digesting all the information :-) and
will try to find some information about algebraic compacity.

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


[Haskell-cafe] Re: Go Haskell!

2009-03-18 Thread Claus Reinke
I finally got around to making my code for random Go playouts available. 
Here it is:


  http://www.haskell.org/~simonmar/goboard.tar.gz


Cool!-) To reciprocate, I've temporarily put a snapshot of my code here:
http://www.cs.kent.ac.uk/~cr3/tmp/SimpleGo.hs

I've not yet decided whether to be depressed or encouraged by the
timings;-) without mercy rule, your code simulates at about 17k/s runs
here, vs only about 3k/s for mine. There are some obvious aspects, such 
as hardcoding the boardsize isn't quite as straightforward when GTP

allows to change it at runtime, but I don't think that explains the bulk
of the difference. I do hope there are lots of small things to learn (perhaps
you could summarize your findings in a performance tips paper?-), but
at first glance, I suspect the difference in approach: my early experiments
suggested that maintaining chains/strings wasn't going to be more efficient
than following the affected parts of strings when needed - but I didn't
think of representing strings as cyclicly referenced lists (which allows
for string merge in constant instead of linear time). Nice idea!-)

Thanks,
Claus



If someone were to make a nice library API on top of this and upload it to 
hackage, I'd be delighted.  Hack away.


A GTP interface would be useful, to allow playing against other bots.


Cheers,
Simon

Simon Marlow wrote:

Claus Reinke wrote:

Do you have an example of a mutable state/ IO bound application, like,
hmm, a window manager or a revision control system or a file system...?


If you're looking for a challenge, how about this one (there used to
be lots of Haskellers into this game, any of you still around?-):

http://computer-go.org/pipermail/computer-go/2008-October/016680.html


[ catching up with old haskell-cafe email ]

Interestingly, I did this a while ago.  Here's my results:

$ ./Bench 1 10
b: 14840, w: 17143 mercy: 67982
elapsed time: 3.42s
playouts/sec: 29208


so, nearly 30k/sec random playouts on 9x9.  That's using a hack that 
stops the game when the score is heavily in favour of one player, it 
drops to around 20k/sec with that turned off.


Not bad, but probably I'd guess an order of magnitude worse than you can 
do in tightly-coded C.  The Haskell implementation isn't nice, as you 
predicted.  Also the code is derived from some non-free internal MS 
code, so unfortunately I can't share it (but I could perhaps extract the 
free bits if anyone is really interested).


W wins slightly more often I think because komi 5.5 on a 9x9 board is a 
tad high.


It does parallelise too, of course:

$ ./Bench 8 10 +RTS -N8
b: 14872, w: 17488 mercy: 67584
elapsed time: 1.00s
playouts/sec: 99908

though still room for improvement there.

Cheers,
Simon



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


[Haskell-cafe] Tweaking the garbage collector for realtime usage

2009-03-18 Thread Peter Verswyvelen
The GHC documentation lists a lot of tweaks that can be done to the garbage
collector.
However, Haskell spin-offs like Timber http://www.timber-lang.org/ implement
their own incremental garbage collector that is better suitable for
real-time usage.

Did someone already fiddle with GHC's gc flags so it works better for
real-time applications, like games and simulations?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] symbolic evaluator for Haskell?

2009-03-18 Thread Tim Newsham
Lambdabot (on #haskell) has something similar using a type, Expr, to overload 
certain names, e.g.


   koninkjefoldr f z [1..5]
   lambdabot  f 1 (f 2 (f 3 (f 4 (f 5 z

It's a complete hack and isn't as sophisticated as what you're after, but it 
could serve as a basis for implementation ideas.


I'm aware of the Expr stuff in lambdabot and elsewhere.  This is not
quite what I need, perhaps I should have picked an example that
doesn't almost-work with Expr.  I need something that will symbolically
evaluate a complex non-numeric expression that makes use of GADTs.

I'm thinking it might not be too hard to implement using TH, but haven't
tried yet...  (though not sure if TH supports GADTs).


Live well,
~wren


Tim Newsham
http://www.thenewsh.com/~newsham/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Tweaking the garbage collector for realtime usage

2009-03-18 Thread Don Stewart
bugfact:
 The GHC documentation lists a lot of tweaks that can be done to the garbage
 collector.
 
 However, Haskell spin-offs like Timber implement their own incremental garbage
 collector that is better suitable for real-time usage.
 
 Did someone already fiddle with GHC's gc flags so it works better for 
 real-time
 applications, like games and simulations?

Galois uses GHC's rts for things that have to have low latency. Useful
tweaks include:

* setting the heap size high
* using the threaded runtime system
* messing with the scheduler tick rate
* patching the rts to avoid slow bits (like deadlock detection)

I think since games and simulations aren't strictly real time you
should be ok.

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


[Haskell-cafe] Haskell Style - Pattern Matching with case vs. function declarations

2009-03-18 Thread Tom.Amundsen

Hi All,

I am new to Haskell. I just started reading Real World Haskell a few days
ago, so I apologize for being such a noob.

But, I am curious why I see a lot of code where people do pattern matching
via multiple function declarations instead of using the case ... of ...
construct? For example:

[code]
foldl' _zero [] = zero
foldl' step zero (x:xs) =
  let new = step zero x
  in  new `seq` foldl' step new xs
[/code]

instead of this, which I prefer:

[code]
foldl' f acc xs = case xs of
[] - acc
(x:xs) - let new = f acc x
  in  new `seq` foldl' f new xs
[/code]
-- 
View this message in context: 
http://www.nabble.com/Haskell-Style---Pattern-Matching-with-case-vs.-function-declarations-tp22584765p22584765.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] encoding for least fixpoint

2009-03-18 Thread Dan Doel
On Wednesday 18 March 2009 5:28:35 am Duncan Coutts wrote:
 You can explain it to yourself (not a proof) by writing out the example
 for lists and co-lists along with fold for the list and unfold function
 for the co-list. Then write conversion functions between them. You can
 go from lists to co-lists using fold or unfold, but going from co-list
 to list requires general recursion. And that's the key of course. In
 Agda or something that distinguishes inductive and co-inductive types
 you could do the first two conversions but not the conversion in the
 other direction.

Yeah, I know how to show it can be done in Haskell. I meant more along the 
lines of a proof (sketch) starting from a definition of a CPO category and 
ending with the fact that initial algebras and terminal coalgebras are the 
same.

Because, of course, in addition to going from, we have general recursion, 
to, least and greatest fixed points are the same, we can do the opposite:

  fix :: (a - a) - a
  fix = cata (\(f,fixf) - f fixf) . ana (\f - (f,f))

I suppose it's obvious that the least fixed point of 'F x = a*x' isn't empty 
in a category like the one people use to model Haskell, because every type is 
inhabited by at least one element, _|_. Once you have that as a base, you can 
construct plenty of elements in ways that would be acceptable even in a total 
language:

  (1, _|_), (2, (1, _|_)), etc.

What remains is to show that you can get the infinite elements somehow (and 
that the greatest fixed point has the above values, but seems less radical).

Anyhow, lastly I wanted to mention to ben that it's probably less hand-wavey 
to explain where you get:

  Mu F = forall x. (F x - x) - x

from by mentioning the paper Build, Augment and Destroy. Universally. That 
develops a slightly tweaked semantics that takes as its basis, for some 
functor F, essentially pairs (Mu' F, fold') where Mu' F is an F-algebra, and 
fold' is obviously similar in function to the cata you get from an initial 
algebra. You define a data type as a limit for such things, which gets you a 
unique morphism that, when you finesse it back into haskell types, gives you:

  build :: (forall x. (F x - x) - x) - Mu F

And the paper of course goes on to show that initial algebras also fit with 
this construction, and vice versa, so the two formulations are equivalent. 
But, the above type looks a lot like the one we had for terminal coalgebras in 
my last mail, so the definition:

  newtype Mu f = Build (forall x. (f x - x) - x)

seems in order. I realize that was still pretty vague, but the paper gives a 
rigorous treatment which should hopefully clear up the details.

(There's an analogous construction for greatest fixed points in the paper, but 
it gets you

  destroy :: (forall x. (x - F x) - x - c) - Nu f - c

which gives you interesting ways to take apart coinductive objects, not build 
them. Of course, I suppose you could recognize that this can be tweaked into:

  destroy :: ((exists x. (x - F x) * x) - c) - Nu f - c

and further suppose that the above is just an identity function, modulo some 
wrapping to make the type nice, which would get you to a similar place.)

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


Re: [Haskell-cafe] Haskell Style - Pattern Matching with case vs. function declarations

2009-03-18 Thread Gwern Branwen

On Wed, Mar 18, 2009 at 1:49 PM, Tom.Amundsen tomamund...@gmail.com wrote:


Hi All,

I am new to Haskell. I just started reading Real World Haskell a few days
ago, so I apologize for being such a noob.

But, I am curious why I see a lot of code where people do pattern matching
via multiple function declarations instead of using the case ... of ...
construct? For example:

[code]
foldl' _    zero []     = zero
foldl' step zero (x:xs) =
     let new = step zero x
     in  new `seq` foldl' step new xs
[/code]

instead of this, which I prefer:

[code]
foldl' f acc xs = case xs of
                           [] - acc
                           (x:xs) - let new = f acc x
                                         in  new `seq` foldl' f new xs
[/code]


Personally, I prefer the former for several reasons: it has less syntax (no 
case...of...-...- stuff), it's easier to manipulate textually, it's less 
indented, and it's somewhat mentally easier to follow, since case feels imperative 
and step-by-step.

Might as well ask why people prefer guard syntax to nesting if-then-elses; 
sure, they may be converted into the same code under the hood and be equivalent 
in power, but one scales better (in terms of clarity).

--
gwern

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


[Haskell-cafe] UNPACK multiple constructors

2009-03-18 Thread Louis Wasserman
{-# UNPACK #-} is specified to work on single-constructor types, but would
there be advantages to, for instance, compiling

data BinTree e = Node e {-# UNPACK #-} !(Maybe (BinTree e)) {-# UNPACK #-}
!(Maybe (BinTree e))

into four constructors, one for each combination of Maybe constructors?
 Thoughts?

Louis Wasserman
wasserman.lo...@gmail.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Style - Pattern Matching with case vs. function declarations

2009-03-18 Thread Zachary Turner
On Wed, Mar 18, 2009 at 12:49 PM, Tom.Amundsen tomamund...@gmail.comwrote:


 Hi All,

 I am new to Haskell. I just started reading Real World Haskell a few days
 ago, so I apologize for being such a noob.

 But, I am curious why I see a lot of code where people do pattern matching
 via multiple function declarations instead of using the case ... of ...
 construct? For example:

 [code]
 foldl' _zero [] = zero
 foldl' step zero (x:xs) =
  let new = step zero x
  in  new `seq` foldl' step new xs
 [/code]

 instead of this, which I prefer:

 [code]
 foldl' f acc xs = case xs of
[] - acc
(x:xs) - let new = f acc x
  in  new `seq` foldl' f new xs
 [/code]


This is just my opinion, but pure functions are often compared to
mathematical functions because they're similar in the way that neither
depend on outside elements, only the inputs.  Consider a mathematical
piecewise function (http://en.wikipedia.org/wiki/Piecewise_function).
These are typically defined as:

f(x) = (*definition 1*)   if condition1
f(x) = (*definition 2*)   if condition2
etc...

(Normally written with a large curly brace, but the idea is still the
same).  To me the notation here matches up nicely with the way of separating
cases by defining them as multiple functions in Haskell because the choice
of notation itself emphasizes that the function can be split into multiple
completely separate computations depending on the format of the input.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] .hi inconsistency bug.

2009-03-18 Thread Joe Fredette
Oh- I see, so The portion of code I have to interpret is already 
separated -- it's not even compiled. The only interpreted code is a 
configuration file in the users home directory. It needs to import some 
chunk of the library (namely, MainTypes and Deliverable) so as to be 
able to export a single routine (filterMain) which gets interpreted at 
run time. But as it stands, I don't even get as far as running that 
code. The problem lies solely in MainTypes proper, which has no dynamic 
code in it or even associated with it. I tried compiling separately and 
together, no dice either way. Somehow, the Email datatype isn't being 
exported from ParseEmail.


However, wrt this:

 and set the source path to plugins directory (using something like 
unsafeSetGhcOption -i./plugins, or set [searchPath

 := [./plugins]], if using the darcs version).

I don't think my hint-related code does this- since my Hint code is 
entirely:


   -- Returns a pair, a path to the inbox location (where new emails 
enter the system) and also
   -- a Filter, the filter delivers (it's a Reader + IO monad) the 
email based on the config+options.

   getFilterMainStuff :: FilePath - Interpreter (Path, Filter ())
   getFilterMainStuff fMainLoc = do
   loadModules [fMainLoc]; setTopLevelModules [(takeWhile 
(/='.') fMainLoc)]

   inboxL - parse $ interpret (inboxLoc) infer
   fMain  - (interpret (filterMain) infer)
   return (inboxL, fMain) 

That is, I load a module, set the TopLevel to include that module, read 
two functions out of that module (one containing the location of the 
inbox to poll, on with the filtering main function) and return them. I 
don't think I need to set any search paths, since fMainLoc is a full 
path. Could this be where my problem is?


Really, I'm just trying to isolate whether it's really Hint causing the 
problem, or something else, because I could always do what xmonad does 
wrt to this- which is (from what I can tell) statically import your 
config file from a given location, which would alleviate all of this, if 
the problem is hint. Perhaps I'll just try that in any case... see if it 
helps.


Thanks again Daniel,

/Joe

Daniel Gorín wrote:
So, if I understand correctly, the interpreter is compiling MainTypes 
twice?


No, the interpreter is trying to compile types that were already 
compiled by the compiler when building your application. The resulting 
types are incompatible.


Could this be a result of having two outputs (one executable and one 
library) in my .cabal file? it _does_ compile those things twice... 
If I create a second cabal file which separates these two different 
packages, would that fix it?


I don't think so. If you already have your application split in 
library part + executable part, then everything should be fine (as 
long as the library is installed before running your application).


The issue is, the (dynamic) interpreter part of my code is part of 
the main loop of the program, and is (as far as I can see) 
inseparable from the rest of the code.


What you need to separate is the code you are planning to interpret in 
runtime. For example, say you have:


src/HackMail/Main.hs
src/HackMail/Data/Types.hs
src/SomePlugin.hs

and SomePlugin.hs is loaded by the interpreter, then you may want to 
reorganize your files like

this:

src/HackMail/Main.hs
src/HackMail/Data/Types.hs
plugins/SomePlugin.hs

and set the source path to plugins directory (using something like 
unsafeSetGhcOption -i./plugins, or set [searchPath := 
[./plugins]], if using the darcs version).


Daniel

I'll give the cabal thing a try, given the incredible triviality of 
doing everything with cabal, I should be done testing the solution 
before I hit the send button... Cabal guys, you rock.


Thanks again, Dan.

/Joe

Daniel Gorín wrote:

Hi

Just a wild guess but maybe the interpreter is recompiling (in 
runtime) code that has already been compiled to build your 
application (in compile-time). This may lead to inconsistencies 
since a type such as HackMail.Data.Main.Types.Filter may refer to 
two different (and incompatible) types.


To see if this is the case, make sure your dynamic code is not 
located together with your base code (i.e., move it to another 
directory, and set the src file directory for the interpreter 
accordingly). Now you may get another runtime error, something along 
the lines of Module not found: HackMail.Data.MainTypes. This 
basically means that you need to make your (already compiled) types 
available to the interpreter. I think the simplest way is to put all 
your support types in a package, register it with ghc, link your 
application to it, and ask the interpreter to use this package (with 
a -package  flag).


Hope this helps!

Daniel

On Mar 17, 2009, at 11:52 PM, Joe Fredette wrote:


List,

I've got this project, source on patch-tag here[1]

It's a nice little project, I've got the whole thing roughly 
working, it compiles okay, everything 

Re: [Haskell-cafe] libgmp for GHC 6.10.1 on Mac OS X 10.5

2009-03-18 Thread David Leimbach
By not using --enable-shared I didn't get this problem.  But now the build
process is complaining about not having link destinations for stuff.
Aren't these makefiles supposed to work?  :-)  I can't figure out what I'm
not or they're not doing so far.  And using a pre-built GHC isn't going to
fly for me, due to the problems of GMP being statically linked.

Dave

On Tue, Mar 17, 2009 at 8:56 PM, David Leimbach leim...@gmail.com wrote:

 Did you get past this point?  I'm hitting:
 == make way=dyn -f GNUmakefile all;
 /Users/dave/Downloads/ghc-6.10.1/ghc/stage1-inplace/ghc -package-name
 ghc-prim-0.1.0.0 -hide-all-packages -no-user-package-conf -split-objs -i
 -idist/build -i. -idist/build/autogen -Idist/build/autogen -Idist/build
 -optP-include -optPdist/build/autogen/cabal_macros.h -odir dist/build -hidir
 dist/build -stubdir dist/build -package rts-1.0 -O -package-name ghc-prim
 -XCPP -XMagicHash -XForeignFunctionInterface -XUnliftedFFITypes
 -XUnboxedTuples -XEmptyDataDecls -XNoImplicitPrelude -fPIC -dynamic -hisuf
 dyn_hi -hcsuf dyn_hc -osuf dyn_o -idist/build  -H32m -O -O2 -Rghc-timing
 -XGenerics -Wall -fno-warn-deprecated-flags -c GHC/PrimopWrappers.hs -o
 dist/build/GHC/PrimopWrappers.dyn_o  -ohi
 dist/build/GHC/PrimopWrappers.dyn_hi
 /var/folders/+U/+U7M7S-rGmSi8lNlphaibU+++TI/-Tmp-//ghc36177_0/ghc36177_0.split__54.s:unknown:missing
 indirect symbols for section (__DATA,__nl_symbol_ptr)
 ghc: 105811188 bytes, 9 GCs, 606208/1093632 avg/max bytes residency (2
 samples), 32M in use, 0.00 INIT (0.00 elapsed), 0.27 MUT (1.97 elapsed),
 0.04 GC (0.05 elapsed) :ghc
 make[3]: *** [dist/build/GHC/PrimopWrappers.dyn_o] Error 1
 make[2]: *** [all] Error 1
 make[1]: *** [make.library.ghc-prim] Error 2
 make: *** [stage1] Error 2

 I would really like to have a ghc that doesn't statically link GMP ;-)

 Dave

 On Sun, Mar 15, 2009 at 9:03 PM, Alan Mock docm...@gmail.com wrote:

 By default GMP builds for x86_64.  Do ./configure ABI=32 to build 32-bit
 libraries for GHC.


 On Mar 15, 2009, at 10:54 PM, Dean Herington wrote:

  I'm trying to install GHC 6.10.1 on Mac OS X 10.5 (PowerPC).  I installed
 Xcode 3.1.2.  I built libgmp 4.2.4 and installed it in /usr/local/lib.  When
 I do ./configure in GHC's dist directory, however, I get:

 bash-3.2$ ./configure
 checking build system type... powerpc-apple-darwin9.6.0
 checking host system type... powerpc-apple-darwin9.6.0
 checking target system type... powerpc-apple-darwin9.6.0
 Which we'll further canonicalise into: powerpc-apple-darwin
 checking for path to top of build tree... dyld: Library not loaded:
 /usr/local/lib/libgmp.3.dylib
  Referenced from:
 /Users/family/Desktop/Downloads/ghc-6.10.1/dist/utils/pwd/pwd
  Reason: no suitable image found.  Did find:
/usr/local/lib/libgmp.3.dylib: mach-o, but wrong architecture
/usr/local/lib/libgmp.3.dylib: mach-o, but wrong architecture
 configure: error: cannot determine current directory

 Any ideas what I'm doing wrong?

 Thanks.
 ___
 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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Need an overview of FP-related research topics

2009-03-18 Thread Bas van Dijk
On Tue, Mar 17, 2009 at 12:59 PM, Yitzchak Gale g...@sefer.org wrote:
 I would like some links that would give such a person
 a nice overview of the various active areas of
 FP-related research these days, leaning towards
 Haskell.

Also check out the Haskell Communities and Activities Report

quote:

The purpose is twofold:
(a) to establish what communities, people, and projects are out there,
working with or on Haskell, and what their areas of interest are;
(b) to feed back summary information about ongoing activities in the
diverse Haskell sub-communities and amongst Haskell users (commercial
or otherwise) to the Haskell Community as a whole

http://www.haskell.org/communities/

Very interesting stuff in there!

regards,

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


Re: [Haskell-cafe] What unsafeInterleaveIO is unsafe

2009-03-18 Thread Jonathan Cast
On Tue, 2009-03-17 at 12:59 +0100, Ketil Malde wrote:
 Duncan Coutts duncan.cou...@worc.ox.ac.uk writes:
 
  [..] I have a sneaking suspicion [exceptions] actually *is* `unsafe'.  Or, 
  at
  least, incapable of being given a compositional, continuous semantics.
 
  Basically if we can only catch exceptions in IO then it doesn't matter,
  it's just a little extra non-determinism and IO has plenty of that
  already.
 
 Couldn't you just substitute catch exceptions with unsafePerformIO
 here, and make the same argument?

This puzzled me, until I realized you meant `unsafeInterleaveIO'.
That's pretty much the argument that is made for unsafeInterleaveIO.

 Similarly, can't you emulate unsafePerformIO with concurrency?

Assuming you mean unsafeInterleaveIO, not quite.  GHC's scheduler is
fair, so you are guaranteed after

forkIO $ a

that a's side effects will happen eventually.  On the other hand, after

unsafeInterleaveIO $ a

you have basically no guarantee the RTS will ever get around to
scheduling a.  (In fact, if you write it just like that in a do block,
rather than saying

x - unsafeInterleaveIO $ a

you are pretty much guaranteed that the RTS won't ever feel like
scheduling a.  It'll even garbage collect a without ever executing it.)

 Further, couldn't you, from IO, FFI into a function that examines the
 source code of some pure function, thus being able to differentiate
 funcitions that are normally indistinguishable?

Regular IO is good enough for this.

 I've tried to follow this discussion, but I don't quite understand
 what's so bad about unsafeInterleaveIO - or rather, what's so uniquely
 bad about it.  It seems the same issues can be found in every corner
 of IO. 

jcc


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


Re: [Haskell-cafe] encoding for least fixpoint

2009-03-18 Thread Dan Doel
On Wednesday 18 March 2009 5:15:32 am Ryan Ingram wrote:
 There's something from Wadler's draft that doesn't make sense to me.  He
 says:

  This introduces a new type, T = Lfix X. F X, satisfying the isomorphism
  T ~ F T.  Note that it is an isomorphism, not an equality:  the type
  comes equipped with functions in : T - F T and out : F T - T.

 While I was able to derive in for Lfix, and out for Gfix, I don't
 think it's possible to derive a generic out for Lfix or in for
 Gfix; maybe such a function *can* always be generated (specific to a
 particular type), but I don't think it's possible to do so while just
 relying on Functor.  Perhaps stronger generic programming methods are
 necessary.

The isomorphism comes from the fact that f (Nu/Mu f) is an f-(co)algebra.

  fmap l_in  :: Functor f = f (f (Mu f)) - f (Mu f)
  fmap g_out :: Functor f = f (Nu f) - f (f (Nu f))

Because of this and initiality/finality, there is a unique morphism from Mu f 
to f (Mu f), and from f (Nu f) to Nu f, namely:

  cata (fmap l_in) :: Functor f = Mu f - f (Mu f)
  ana (fmap g_out) :: Functor f = f (Nu f) - Nu f

where

  cata f (Lfix k) = k f
  ana g x = Gfix g x

Of course, this isomorphism is subject to caveats about bottom and seq in 
Haskell.

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


Re: [Haskell-cafe] Query on list comprehension

2009-03-18 Thread Henning Thielemann


On Tue, 17 Mar 2009, Melanie_Green wrote:


What are the limitations of list comprehension. I want to use
listcomprehension to output the pattern below. So a mixture of a's and
newline characters. The part im stuck at is creating arguments in the
listcomprehension to stop at some point then execute next loop. Is it even
possible to create the pattern below purely from list comprehension.Thankyou
in advance.

a
aa
aaa


iterate ('a':) \n
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] server directory layout for cabal-install?

2009-03-18 Thread Johannes Waldmann
Hello.

I wonder what is the required layout of directories
and files on a server that supplies packages for cabal-install.

I figure 00-index.tar.gz contains the *.cabal files.
(The cabal files have to be on the server as well, unpacked?)
Each $dir/$foo.cabal (in the archive) contains a Version:$ver line,
and then $dir/$foo-$ver.tar.gz  must be on the server?
Are there additional constraints on the $dir part?

What is the syntax of the .cabal/config file? The standard entry is
repos: hackage.haskell.org:http://hackage.haskell.org/packages/archive ,
where the thing between repos: and :http is just a symbolic name,
and I can add more lines like that?

Thanks, J.W.



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


Re: [Haskell-cafe] encoding for least fixpoint

2009-03-18 Thread Ryan Ingram
On Wed, Mar 18, 2009 at 8:10 AM, David Menendez d...@zednenem.com wrote:
 l_out :: Functor f = Lfix f - f (Lfix f)
 l_out = cata (fmap l_in)

 g_in :: Functor f = f (Gfix f) - Gfix f
 g_in = ana (fmap g_out)

OK, I understand these now.

But they both seem to have significant performance implications, which
I think are related to the tail-in-terms-of-foldr problem.

Consider this definition:

safeTail [] = []
safeTail (x:xs) = xs

The simplest way to write this directly with foldr is:

safeTail' = fst . foldr f ([], []) where
   f x (t, l) = (l, x:l)

But the difference is that safeTail' here reconstructs the list from
scratch, instead of reusing the existing data as safeTail does.  This
means that (safeTail . safeTail . safeTail ...) takes O(n^2) time
instead of O(n).

Similarily, l_out and g_in both seem to add many administrative
redexes to every element of the object being manipulated; consider

gid = g_in . g_out

then consider
  (gid . gid . gid . gid) x

The result gets filled up quickly with administrative redexes that look like
  Gfix (fmap g_out) $ g_out $ Gfix (fmap g_out) $ g_out $ Gfix ...

Is there a way to solve this problem and still maintain the nice
totality guarantees that you get from System F without fix?

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


Re: [Haskell-cafe] Who generates Haskell code and uses type information at runtime? (fwd)

2009-03-18 Thread Duane Johnson
Out of curiosity, do you know if HaRe works for 6.10?  The page only  
mentions GHC 6.6 and 6.8.


Duane Johnson
http://blog.inquirylabs.com/


On Mar 18, 2009, at 6:14 AM, Chris Brown wrote:

I'm not sure if you got my previous message, as I was having some  
problems posting to the list...



Putting in a nutshell, I generalize an extensional defined function
definition into a recursive one. This is done in a number of steps by
modifying expressions and exploiting type information of
sub-expressions. For example:
rev [] = []
rev [a] = [a]
rev [a,b] = [b,a]
rev [a,b,c] = [c,b,a]
~~
rev x = y
~~
rev [] = []
rev (x:xs) = (y:ys)
~~
rev [] = []
rev (x:xs) = (last (x:xs)) : (reverse (x:xs))
The initial set of rules is given by the user (in a file, via  
IO, ...).
The problem later is to infer the type of an intermediate variable,  
e.g.

'y'.


I'm still not entirely sure what you want to do here. But it sounds  
like HaRe could already do most of this for you via a sequence of  
folds, unfolds, introduce pattern matching and generative folding.  
HaRe already has built-in support for some symbolic evaluation,  
which is already used in the generative

fold refactoring, and has type checking support too.

http://www.cs.kent.ac.uk/projects/refactor-fp/hare.html

If it doesn't do exactly what you want out of the tin, it does have  
a large API for designing transformations over Haskell code.


http://www.cs.kent.ac.uk/projects/refactor-fp/hare/haddock/RefacUtils.html



Chris.





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



--
Chris Brown

Visualization Software Engineer, Peiriannydd Meddalwedd Delweddu.

Cast Ltd., Technium CAST,
Ffordd Penlan, Parc Menai,
Bangor, Gwynedd UK. LL57 4HJ.

Tel: +44 (0)1248 675038
Fax: +44 (0)1248 675012
Mobile: +44 (0)7917 763712


--
Centre for Advanced Software Technology Limited is a limited company  
registered in England and Wales.
Registered Number: 04473521, Registered Office: Finance Office,  
Bangor University, College Road, Bangor, Gwynedd. LL57 2DG.


___
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] .hi inconsistency bug.

2009-03-18 Thread Joe Fredette
I seem to have fixed this bug, only to find another- the issue was that 
I misunderstood what Cabal means by exposed modules upon exposing all 
of the modules MainTypes uses, the problem resolved itself. I now have 
another problem, having to do with importing the file from 
$HOME/.hackmail, but I'm going to take a crack at it before bothering 
the list again. Thanks very much Daniel,


/Joe

Daniel Gorín wrote:
So, if I understand correctly, the interpreter is compiling MainTypes 
twice?


No, the interpreter is trying to compile types that were already 
compiled by the compiler when building your application. The resulting 
types are incompatible.


Could this be a result of having two outputs (one executable and one 
library) in my .cabal file? it _does_ compile those things twice... 
If I create a second cabal file which separates these two different 
packages, would that fix it?


I don't think so. If you already have your application split in 
library part + executable part, then everything should be fine (as 
long as the library is installed before running your application).


The issue is, the (dynamic) interpreter part of my code is part of 
the main loop of the program, and is (as far as I can see) 
inseparable from the rest of the code.


What you need to separate is the code you are planning to interpret in 
runtime. For example, say you have:


src/HackMail/Main.hs
src/HackMail/Data/Types.hs
src/SomePlugin.hs

and SomePlugin.hs is loaded by the interpreter, then you may want to 
reorganize your files like

this:

src/HackMail/Main.hs
src/HackMail/Data/Types.hs
plugins/SomePlugin.hs

and set the source path to plugins directory (using something like 
unsafeSetGhcOption -i./plugins, or set [searchPath := 
[./plugins]], if using the darcs version).


Daniel

I'll give the cabal thing a try, given the incredible triviality of 
doing everything with cabal, I should be done testing the solution 
before I hit the send button... Cabal guys, you rock.


Thanks again, Dan.

/Joe

Daniel Gorín wrote:

Hi

Just a wild guess but maybe the interpreter is recompiling (in 
runtime) code that has already been compiled to build your 
application (in compile-time). This may lead to inconsistencies 
since a type such as HackMail.Data.Main.Types.Filter may refer to 
two different (and incompatible) types.


To see if this is the case, make sure your dynamic code is not 
located together with your base code (i.e., move it to another 
directory, and set the src file directory for the interpreter 
accordingly). Now you may get another runtime error, something along 
the lines of Module not found: HackMail.Data.MainTypes. This 
basically means that you need to make your (already compiled) types 
available to the interpreter. I think the simplest way is to put all 
your support types in a package, register it with ghc, link your 
application to it, and ask the interpreter to use this package (with 
a -package  flag).


Hope this helps!

Daniel

On Mar 17, 2009, at 11:52 PM, Joe Fredette wrote:


List,

I've got this project, source on patch-tag here[1]

It's a nice little project, I've got the whole thing roughly 
working, it compiles okay, everything seems to work, until I try to 
run it, specifically when I run it in ghci, or when I run the main 
executable (which uses hint), and look at any type involving my 
Email type, it gives me the following error:


Type syonym HackMail.Data.MainTypes.Filter:
  Can't find interface-file declaration for type constructor or 
class HackMail.Data.ParseEmail.Email

Probable cause: bug in .hi-boot file, or inconsistent .hi file
Use -ddump-if-trace to get an idea of which file caused the error

As far as I understand, it wants to find the interface-file 
declaration for a specific type (Email) exported by the ParseEmail 
module, all of the exports (I think) are in order. I've tried 
mucking around with it a bit, but I don't fully understand what the 
error even means, much less how to fix it.


Other relevant info, Email is exported in a roundabout way, namely 
by importing a module MainTypes, which exports a module Email, 
which exports a the ParseEmail Module, which exports the datatype 
Email.


The Filter delcaration it _actually_ complains about (it's just 
the first place the email type is invoked) is:


type Filter a = ReaderT (Config, Email) IO a

nothing particularly special.

Any help fixing this is greatly appreciated, I did find this bug 
report[2] which seems like it might be relevant.


But trying to unregister - cabal clean - cabal install doesn't 
fix it. I've also tried manually removing the dist/ folder, and 
also unregistering the package.


Thanks again.

/Joe

[1] http://patch-tag.com/repo/Hackmail/browse
[2] http://hackage.haskell.org/trac/ghc/ticket/2057
jfredett.vcf___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




jfredett.vcf



begin:vcard

[Haskell-cafe] Summer Of Code 2009 project idea

2009-03-18 Thread Csaba Hruska
Hi!

I'd like to participate in gsoc2009.
My project idea is to complete my initial render backend (
http://www.haskell.org/haskellwiki/LambdaCubeEngine) what can be useful for
(possibe more) haskell projects.
I'd like to extend it to support physics (reusing hpysics source code), etc.

Current features:
 + easy (from user view) model loading and rendering
 + definig materials (texture layers, blending setup, shaders, etc) via
readable material scripts
 + fast rendering via vertex buffers

Some planned features:
 + skeletal animation (in progress)
 + physics (hpysics) integration
 + efficient terrain rendering
 + some mesh modifier combinators
 etc..

Do you think is this useful? Or should i think out a more relevant idea?

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


Re: [Haskell-cafe] Summer Of Code 2009 project idea

2009-03-18 Thread Peter Verswyvelen
Well if you can do all that in a summer then you have been *very* productive
:-)
Haskell is indeed lacking a good functional 3D render engine (besides
Fieldtrip which is more academic), but I'm not sure the community is waiting
for this.

But personally I am all for it :-)

2009/3/18 Csaba Hruska csaba.hru...@gmail.com

 Hi!

 I'd like to participate in gsoc2009.
 My project idea is to complete my initial render backend (
 http://www.haskell.org/haskellwiki/LambdaCubeEngine) what can be useful
 for (possibe more) haskell projects.
 I'd like to extend it to support physics (reusing hpysics source code),
 etc.

 Current features:
  + easy (from user view) model loading and rendering
  + definig materials (texture layers, blending setup, shaders, etc) via
 readable material scripts
  + fast rendering via vertex buffers

 Some planned features:
  + skeletal animation (in progress)
  + physics (hpysics) integration
  + efficient terrain rendering
  + some mesh modifier combinators
  etc..

 Do you think is this useful? Or should i think out a more relevant idea?

 Cheers,
 Csaba Hruska

 ___
 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] Google Summer of Code

2009-03-18 Thread Malcolm Wallace
I am pleased to announce that haskell.org has once again been accepted  
as a mentoring organisation, for the 2009 Google Summer of Code.   
Student applications open on Monday (23rd March) at 1900 UTC, for a  
period of 12 days (until Fri 3rd April, also at 1900 UTC).


Students applicants are encouraged to interact with the community via  
mailing lists, prior, during, and after the submission of their ideas  
for projects.
In general terms, project ideas that benefit the whole community (e.g.  
infrastructure like ghc, cabal, libraries) will be preferred over  
things of more marginal interest (e.g. games).  Unless you make a  
_really_ good case, of course!


Because (sadly) the darcs community did not get accepted as a separate  
organisation this year, haskell.org will be willing to accept  
proposals relating to darcs (as it has done in previous years), but of  
course they will be competing in the general pool, alongside all the  
other ideas.


Also, we are still accepting mentors.

Regards,
Malcolm

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


[Haskell-cafe] Any way to catch segmentation fault?

2009-03-18 Thread Nick Rudnick
Hi all,

doing some work with a regex library I stumbled over some segmentation
faults due to illegal byte combinatations.

Looking for a way to get this caught some way, I failed in finding any place
at GHC (6.10.1) or Hackage libraries where this is covered -- a quick check
with HUnit revealed it to be crashing by this phenomenon.

So I would like to ask about the state of this issue,

o   Is there principally no way to (generally) catch segmentation faults??
(This would be hard to believe, as the described kind of noise is to be
expected at production systems, especially with user generated content.)

o   Are segmentation faults «prohibited» in Haskell so the advice is just to
change the used library and forget the whole stuff??

o   Did I oversee the generic mechanism for catching of segmentation
faults?? (If yes, do you please give me a hint??)

o   If no, is there a workaround which might be practicable??


Thanks a lot in advance,

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


Re: [Haskell-cafe] Any way to catch segmentation fault?

2009-03-18 Thread Brandon S. Allbery KF8NH

On 2009 Mar 18, at 19:44, Nick Rudnick wrote:
o   Is there principally no way to (generally) catch segmentation  
faults?? (This would be hard to believe, as the described kind of  
noise is to be expected at production systems, especially with user  
generated content.)


System.Posix.Signals.  But your assumption is wrong, considering that  
after a segfault occurs there are no guarantees that the runtime  
(whether for Haskell or C) is in a sane state.


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




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


[Haskell-cafe] hw do i solve this problems:

2009-03-18 Thread THANDO NTUANE
kindly help me..
im stack but managed to solve exercise 1 and 2.



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


[Haskell-cafe] Fw: hw do i solve this problems:

2009-03-18 Thread THANDO NTUANE




- Forwarded Message 
From: THANDO NTUANE thandodar...@yahoo.com
To: Haskell-Cafe@haskell.org
Sent: Thursday, March 19, 2009 10:22:40 AM
Subject: hw do i solve this problems:


kindly help me..
im stack but managed to solve exercise 1 and 2.


  

task1.docx
Description: application/vnd.openxmlformats-officedocument.wordprocessingml.document
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Fw: hw do i solve this problems:

2009-03-18 Thread Zachary Turner
2009/3/18 THANDO NTUANE thandodar...@yahoo.com



 - Forwarded Message 
 *From:* THANDO NTUANE thandodar...@yahoo.com
 *To:* Haskell-Cafe@haskell.org
 *Sent:* Thursday, March 19, 2009 10:22:40 AM
 *Subject:* hw do i solve this problems:

 kindly help me..
 im stack but managed to solve exercise 1 and 2.


I feel like this is a homework assignment, which if that's the case it would
be more appropriate for reasons of academic honesty to ask your professor or
TA for assistance.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Fw: hw do i solve this problems:

2009-03-18 Thread Conrad Meyer
On Wednesday 18 March 2009 07:39:16 pm Zachary Turner wrote:
 I feel like this is a homework assignment, which if that's the case it
 would be more appropriate for reasons of academic honesty to ask your
 professor or TA for assistance.

Furthermore I have nothing to open .docx files with, at least do the list the 
courtesy of providing a pdf or something. But this is a homework question, and 
not even an intelligent one at that.

-- 
Conrad Meyer kon...@tylerc.org

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


[Haskell-cafe] Announce: language-python

2009-03-18 Thread Bernie Pope
Language-python provides a parser (and lexer) for Python written in  
Haskell. Currently it only supports version 3 of Python (the most  
recent version), but it will support version 2 in the future.


The parser is implemented using Happy, and the lexer is implemented  
using Alex.


Web page: http://projects.haskell.org/language-python/

Hackage: 
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/language-python

Darcs: darcs get http://code.haskell.org/language-python/

Example:
$ ghci
Prelude :m Language.Python.Version3.Parser
Prelude Language.Python.Version3.Parser parseModule def inc(x):  
return x + 1\n []
Right (Module [Fun {fun_name = Ident inc, fun_args = [Param  
{param_name = Ident x, param_annotation = Nothing, param_default =  
Nothing}], fun_result_annotation = Nothing, fun_body = [Return  
{return_expr = Just (BinaryOp {operator = Plus, left_op_arg = Var  
(Ident x), right_op_arg = Int 1})}]}])


Prelude Language.Python.Version3.Parser :m  
Language.Python.Version3.Lexer
Prelude Language.Python.Version3.Lexer lexOneToken def inc(x):  
return x + 1\n []
Right (Def (Sloc {sloc_filename = , sloc_row = 1, sloc_column =  
1}), inc(x): return x + 1\n)


This is the first release of the package (version 0.1.1) and there is  
still much to be improved, in particular:

   - Unicode support is incomplete.
   - Source locations are sub-optimal, and will eventually become  
source spans.

   - The pretty printer needs polish.
   - The parser only supports version 3 of Python. Support for  
Version 2 is a major goal, and should be straightforward.
   - Only minimal performance tuning and correctness testing has been  
performed. Version 0.1.1 is not intended for production use.


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


[Haskell-cafe] Re: Haskell Logo Voting has started!

2009-03-18 Thread Benjamin L . Russell
On Wed, 18 Mar 2009 11:36:15 +0100, Wolfgang Jeltsch
g9ks1...@acme.softbase.org wrote:

Am Mittwoch, 18. Marz 2009 10:03 schrieb Benjamin L.Russell:
 Just go through the list, choose your top favorite, and assign rank 1
 to it;

Is rank 1 the best or the worst?

On your voting page referenced in a message, entitled CIVS Poll now
available for voting: Haskell Logo Competition from Eelco Lempsink,
the CIVS poll supervisor (which should have been sent to your e-mail
address), the following paragraph describes the meaning of the ranks:

Give each of the following choices a rank, where a smaller-numbered rank 
means that you prefer that choice more. For example, it would make sense 
to give your top choice (or choices) the rank 1. You may give choices the 
same rank if you have no preference between them. You do not have to use 
all the possible ranks. All choices are initially given the lowest possible 
rank.

Therefore, rank 1 is the best.

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

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


Re: [Haskell-cafe] Haskell Style - Pattern Matching with case vs. function declarations

2009-03-18 Thread Luke Palmer
On Wed, Mar 18, 2009 at 11:49 AM, Tom.Amundsen tomamund...@gmail.comwrote:


 Hi All,

 I am new to Haskell. I just started reading Real World Haskell a few days
 ago, so I apologize for being such a noob.

 But, I am curious why I see a lot of code where people do pattern matching
 via multiple function declarations instead of using the case ... of ...
 construct? For example:

 [code]
 foldl' _zero [] = zero
 foldl' step zero (x:xs) =
  let new = step zero x
  in  new `seq` foldl' step new xs
 [/code]


Well, in this particular case, note that you have two equations written.
These equations are true of foldl', and in fact foldl' is the *least defined
* function satisfying these equations (see
http://en.wikibooks.org/wiki/Haskell/Denotational_semantics for the
underlying theory of definedness).  It a very pretty idea.

However, this happy view of equations breaks down once you start using the
fall through semantics, as in:

foo (x:y:xs) = x + y
foo xs = 0

In which the second equation does not always hold (foo [1,2,3] = 0 is
false).  Because of this, I am beginning to prefer not writing functions
using fall through, although occasionally it is too damned convenient to
pass up.

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


Re: [Haskell-cafe] Re: Memoizing partially evaluated computations.

2009-03-18 Thread Luke Palmer
On Wed, Mar 18, 2009 at 6:21 AM, Chung-chieh Shan
ccs...@post.harvard.eduwrote:

 Sebastiaan Visser sfvis...@cs.uu.nl wrote in article 
 d86a7d11-f95f-4a27-a13c-2d78afda2...@cs.uu.nl in
 gmane.comp.lang.haskell.cafe:
  Suppose I have a list of IO computations that depends on a few very
  time consuming pure operations. The pure operations are not dependent
  on the real world:
 
 computation :: [IO Int]
 computation = [
 smallIOfunc timeConsumingPureOperation0
   , smallIOfunc timeConsumingPureOperation1
   , smallIOfunc timeConsumingPureOperation2
   , smallIOfunc timeConsumingPureOperation3
   ]
   where smallIOfunc a = print a  return a

 I take it that, because you do not really have the control to change
 things `deep' inside the code, it is not an option to redefine

computation = [
smallIOfunc x0
  , smallIOfunc x1
  , smallIOfunc x2
  , smallIOfunc x3
   ]
  where smallIOfunc a = print a  return a
 x0 = timeConsumingPureOperation0
x1 = timeConsumingPureOperation1
x2 = timeConsumingPureOperation2
x3 = timeConsumingPureOperation3


Um, just to clarify, this code is exactly equivalent to the original,
including sharing behavior.  The only time a let (or where) clause changes
sharing is if the variable is used more than once in the body.

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


[Haskell-cafe] Crash in GHCI - what is the correct behavior here?

2009-03-18 Thread Zachary Turner
Basically just learning haskell, I would have posted this in the beginners
list but since it involves a segfault of GHCI, I figured it might be worth
posting here.

I was trying to get a good understanding of local variable scoping issues,
so I tried the following:

f :: (Num a) = a - a
f x =
let p = x*x
in
let p = x*p
in p

I have some background in ML, which led me to believe that what should
happen here is that the function would return x^3.  Instead, GHCI just
completely terminates, I guess with a segfault.  What's the correct
behavior here?  Should it even compile?  I understand that you can't
redefine the same symbol twice in the same scope, so I tried this
specifically to see what would happen if you defined the same variable again
in a nested scope.  I thought it would just shadow the original declaration,
while still using the original p to calculate the value of the new p.  I
don't think the problem is the re-declaration of the same symbol in a nested
scope (although if someone could clarify that would be nice), but rather the
fact that I've attempted to use the previous declaration of p in defining
the new declaration of p.

Would it be a safe assumption that a bug report should be submitted over
this?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Memoizing partially evaluated computations.

2009-03-18 Thread Chung-chieh Shan
On 2009-03-18T21:24:58-0600, Luke Palmer wrote:
 On Wed, Mar 18, 2009 at 6:21 AM, Chung-chieh Shan
 ccs...@post.harvard.eduwrote:
 computation = [
 smallIOfunc x0
   , smallIOfunc x1
   , smallIOfunc x2
   , smallIOfunc x3
]
   where smallIOfunc a = print a  return a
  x0 = timeConsumingPureOperation0
 x1 = timeConsumingPureOperation1
 x2 = timeConsumingPureOperation2
 x3 = timeConsumingPureOperation3
 
 Um, just to clarify, this code is exactly equivalent to the original,
 including sharing behavior.  The only time a let (or where) clause changes
 sharing is if the variable is used more than once in the body.

Ah, good point!  Of course, timeConsumingPureOperation0 above is a
metavariable for a Haskell expression, not just a Haskell variable.  But
I guess I also took smallIOfunc to be a metavariable for a Haskell
context (i.e., a Haskell expression with a hole), not just a Haskell
function name.

You make an important point that sharing is changed only if the variable
(such as x0) is used more than once in the body.  Let me note that the
definition of computation doesn't have to mention x0 multiple times
syntactically for x0 to be used more than once.  It's enough for x0 to
appear once under a lambda.  Here's a concrete example:

main :: IO ()
main = once  once

once :: IO ()
once = do
putStrLn foo
putStrLn (unsafePerformIO (putStrLn hello) `seq` world)

If I put () - in front of the second-to-last line, then hello
appears twice, not once, in the output.

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
100 Days to close Guantanamo and end torture http://100dayscampaign.org/
http://www.avaaz.org/en/end_the_war_on_terror/


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


Re: [Haskell-cafe] Crash in GHCI - what is the correct behavior here?

2009-03-18 Thread Luke Palmer
2009/3/18 Zachary Turner divisorthe...@gmail.com

 Basically just learning haskell, I would have posted this in the beginners
 list but since it involves a segfault of GHCI, I figured it might be worth
 posting here.

 I was trying to get a good understanding of local variable scoping issues,
 so I tried the following:

 f :: (Num a) = a - a
 f x =
 let p = x*x
 in
 let p = x*p
 in p

 I have some background in ML, which led me to believe that what should
 happen here is that the function would return x^3.  Instead, GHCI just
 completely terminates, I guess with a segfault.  What's the correct
 behavior here?  Should it even compile?  I understand that you can't
 redefine the same symbol twice in the same scope, so I tried this
 specifically to see what would happen if you defined the same variable again
 in a nested scope.  I thought it would just shadow the original declaration,
 while still using the original p to calculate the value of the new p.  I
 don't think the problem is the re-declaration of the same symbol in a nested
 scope (although if someone could clarify that would be nice), but rather the
 fact that I've attempted to use the previous declaration of p in defining
 the new declaration of p.


You are correct that the inner p shadows the outer p.  However, you are
incorrect that p on the right side of the inner definition is the outer p
(man this is hard to talk about).  Lets in Haskell are recursive, so your
program is equivalent to:

f x = let p = x*p in p

I'm going to do a little domain theory now, because I'm in the mood :-).  So
p is the least value which satisfies the equation p = x*p.  For most numeric
types, (*) is strict in its right argument, so _|_ = x*_|_.  And in fact
this is the equation we had to satisfy, and there is no value less than _|_,
so p = _|_.

So, f x = _|_. (an infinite loop)

I love Haskell so much.  T'aint no language more precise.

Anyway, there are various ways that Haskell handles bottom.  If you're
seeing ghci immediately exit, you're probably observing black hole
detection, in which ghci prints loop to inform you you have an infinite
loop instead of actually looping forever.  There are certain cases where
this can be done.

If that's not consistent with what you observed, more details please!
Including version, OS, compiler flags, and transcript.  It might indeed be a
bug :-)

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


Re: [Haskell-cafe] Crash in GHCI - what is the correct behavior here?

2009-03-18 Thread Zachary Turner
On Wed, Mar 18, 2009 at 11:46 PM, Luke Palmer lrpal...@gmail.com wrote:

 2009/3/18 Zachary Turner divisorthe...@gmail.com

 Basically just learning haskell, I would have posted this in the beginners
 list but since it involves a segfault of GHCI, I figured it might be worth
 posting here.

 I was trying to get a good understanding of local variable scoping issues,
 so I tried the following:

 f :: (Num a) = a - a
 f x =
 let p = x*x
 in
 let p = x*p
 in p

 I have some background in ML, which led me to believe that what should
 happen here is that the function would return x^3.  Instead, GHCI just
 completely terminates, I guess with a segfault.  What's the correct
 behavior here?  Should it even compile?  I understand that you can't
 redefine the same symbol twice in the same scope, so I tried this
 specifically to see what would happen if you defined the same variable again
 in a nested scope.  I thought it would just shadow the original declaration,
 while still using the original p to calculate the value of the new p.  I
 don't think the problem is the re-declaration of the same symbol in a nested
 scope (although if someone could clarify that would be nice), but rather the
 fact that I've attempted to use the previous declaration of p in defining
 the new declaration of p.


 You are correct that the inner p shadows the outer p.  However, you are
 incorrect that p on the right side of the inner definition is the outer p
 (man this is hard to talk about).  Lets in Haskell are recursive, so your
 program is equivalent to:

 f x = let p = x*p in p

 I'm going to do a little domain theory now, because I'm in the mood :-).
 So p is the least value which satisfies the equation p = x*p.  For most
 numeric types, (*) is strict in its right argument, so _|_ = x*_|_.  And in
 fact this is the equation we had to satisfy, and there is no value less than
 _|_, so p = _|_.

 So, f x = _|_. (an infinite loop)

 I love Haskell so much.  T'aint no language more precise.

 Anyway, there are various ways that Haskell handles bottom.  If you're
 seeing ghci immediately exit, you're probably observing black hole
 detection, in which ghci prints loop to inform you you have an infinite
 loop instead of actually looping forever.  There are certain cases where
 this can be done.

 If that's not consistent with what you observed, more details please!
 Including version, OS, compiler flags, and transcript.  It might indeed be a
 bug :-)


Regarding the black hole detection, is GHCI supposed to exit after
printing loop?  Or is just supposed to print loop then return to a GHCI
prompt?  Here's a transcript:

C:\Documents and Settings\Zachghci
GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude let f x = let p = x*x in let p = x*p in p
Prelude f 7

C:\Documents and Settings\Zach

That's it.  This is on Windows XP Service Pack 2.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Memoizing partially evaluated computations.

2009-03-18 Thread Luke Palmer
On Wed, Mar 18, 2009 at 10:37 PM, Chung-chieh Shan
ccs...@post.harvard.eduwrote:

 You make an important point that sharing is changed only if the variable
 (such as x0) is used more than once in the body.  Let me note that the
 definition of computation doesn't have to mention x0 multiple times
 syntactically for x0 to be used more than once.  It's enough for x0 to
 appear once under a lambda.  Here's a concrete example:

main :: IO ()
main = once  once

once :: IO ()
once = do
putStrLn foo
putStrLn (unsafePerformIO (putStrLn hello) `seq` world)

 If I put () - in front of the second-to-last line, then hello
 appears twice, not once, in the output.


You're right.  Of course, now you're in the compiler's territory.  If you
compile the () - version with optimizations, the unsafePerformIO is lifted
out and hello is again only printed once.  So yes, to ensure sharing under
a lambda, it's safest to use an explicit let/where clause.

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


Re: [Haskell-cafe] Crash in GHCI - what is the correct behavior here?

2009-03-18 Thread Luke Palmer
On Wed, Mar 18, 2009 at 10:55 PM, Zachary Turner divisorthe...@gmail.comwrote:

 Regarding the black hole detection, is GHCI supposed to exit after
 printing loop?  Or is just supposed to print loop then return to a GHCI
 prompt?  Here's a transcript:

 C:\Documents and Settings\Zachghci
 GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
 Loading package ghc-prim ... linking ... done.
 Loading package integer ... linking ... done.
 Loading package base ... linking ... done.
 Prelude let f x = let p = x*x in let p = x*p in p
 Prelude f 7

 C:\Documents and Settings\Zach


Hmm, that's weird.  I note that here on linux, this expression gobbles up
memory like nobody's business.  Maybe it's being killed for eating too
much?  (I dunno)

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