Re: [Haskell-cafe] DpH/repa cache locality

2010-07-13 Thread Dominique Devriese
Hi,

2010/7/13 Gregory Crosswhite gcr...@phys.washington.edu:
 Just out of curiosity, what work is being done in the data parallel
 haskell / repa projects regarding cache locality?
Hi,

I'm not knowledgeable at all about this, but for a technical
introduction to DPH, I found the following excellent. Locality
is a recurring theme in the talk, IIRC. (Sorry for the double reply)

http://www.youtube.com/watch?v=NWSZ4c9yqW8

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


[Haskell-cafe] Please report any bug of gtk2hs-0.11.0!

2010-07-13 Thread Andy Stewart
Hi all,

We plan to release bug fix version : gtk2hs-0.11.1

Please report any bug of gtk2hs-0.11.0, we will fix it before release
gtk2hs-0.11.1

We plan to add many new APIs in gtk2hs-0.12.0, 
so gtk2hs-0.11.1 will be the last stable version with current APIs.

Thanks for your help!

  -- Andy




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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Haskell 2010 Report (final)

2010-07-13 Thread Simon Marlow

On 12/07/2010 18:29, Felipe Lessa wrote:

On Mon, Jul 12, 2010 at 9:50 AM, Simon Marlowmarlo...@gmail.com  wrote:

And hopefully things will improve over time, as fewer packages will need to
depend on base.  We could also start pulling out APIs that are currently in
base into separate packages, without actually pulling out the code - e.g.
concurrency, and that would be a good way to migrate people away from
depending on base, but without breaking everything.


Is the plan to stop using base and start using 'haskell2010', even if
you use extensions that aren't Haskell 2010?


You can make an independent choice about whether to use the Haskell 2010 
language, and/or the Haskell 2010 libraries.


If you need to use modules from base that are not part of Haskell 2010, 
then you will not be able to use the haskell2010 package, but you will 
still be able to use {-# LANGUAGE Haskell2010 #-}.


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


[Haskell-cafe] lists of arbitrary depth

2010-07-13 Thread vadali

hello, 
iam really new to haskell, 

i want to define a function which takes as a parameter a list which can
contain other lists, eg. [1,[2,3],[4,[5,6]]]

how would i define a function that can iterate through the items so (in this
example)
iter1 = 1
iter2 = [2,3]
iter3 = [4,[5,6]]

?

( can i do that without using the Tree data type? )

THANKS!

-- 
View this message in context: 
http://old.nabble.com/lists-of-arbitrary-depth-tp29139641p29139641.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] lists of arbitrary depth

2010-07-13 Thread Christopher Done
On 13 July 2010 10:58, vadali shlomivak...@gmail.com wrote:

 hello,
 iam really new to haskell,

 i want to define a function which takes as a parameter a list which can
 contain other lists, eg. [1,[2,3],[4,[5,6]]]

 how would i define a function that can iterate through the items so (in this
 example)
 iter1 = 1
 iter2 = [2,3]
 iter3 = [4,[5,6]]

 ?

 ( can i do that without using the Tree data type? )

Maybe this should be moved to Haskell-Beginnners.

It's impossible to have a function that works on a list of arbitrary
nesting. But you could use a tree data type, yeah.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] lists of arbitrary depth

2010-07-13 Thread Johan Tibell
Hi Vadali,

On Tue, Jul 13, 2010 at 10:58 AM, vadali shlomivak...@gmail.com wrote:


 hello,
 iam really new to haskell,

 i want to define a function which takes as a parameter a list which can
 contain other lists, eg. [1,[2,3],[4,[5,6]]]

 how would i define a function that can iterate through the items so (in
 this
 example)
 iter1 = 1
 iter2 = [2,3]
 iter3 = [4,[5,6]]

 ?

 ( can i do that without using the Tree data type?


No, a list contains a homogeneous sequence of values (i.e. a sequence of
values of the same type). If you explain what you're trying to achieve we
might be able to offer you better help.

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


Re: [Haskell-cafe] lists of arbitrary depth

2010-07-13 Thread Ivan Lazar Miljenovic
vadali shlomivak...@gmail.com writes:

 hello, 
 iam really new to haskell, 

 i want to define a function which takes as a parameter a list which can
 contain other lists, eg. [1,[2,3],[4,[5,6]]]

 how would i define a function that can iterate through the items so (in this
 example)
 iter1 = 1
 iter2 = [2,3]
 iter3 = [4,[5,6]]

 ?

 ( can i do that without using the Tree data type? )

Well, that's what a tree is, so why not use a tree?

Your only other option is to define your own tree-like structure:

data MyTree a = Value a | SubTree [MyTree a]


 THANKS!

YOUR WELCOME! :p

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] lists of arbitrary depth

2010-07-13 Thread Shlomi Vaknin
Thank you all for replying!

I am really beginning my baby steps in this fascinating language, and was
just wondering if it was possible to naturally scan lists with arbitrary
lists (aka trees :) ).

I guess this forum specifically is too advancaed for me (yet!), so my next
questions will be posted on the beginners forum.

Thanks,
Vadali

On Tue, Jul 13, 2010 at 11:07 AM, Ivan Lazar Miljenovic 
ivan.miljeno...@gmail.com wrote:

 vadali shlomivak...@gmail.com writes:

  hello,
  iam really new to haskell,
 
  i want to define a function which takes as a parameter a list which can
  contain other lists, eg. [1,[2,3],[4,[5,6]]]
 
  how would i define a function that can iterate through the items so (in
 this
  example)
  iter1 = 1
  iter2 = [2,3]
  iter3 = [4,[5,6]]
 
  ?
 
  ( can i do that without using the Tree data type? )

 Well, that's what a tree is, so why not use a tree?

 Your only other option is to define your own tree-like structure:

 data MyTree a = Value a | SubTree [MyTree a]

 
  THANKS!

 YOUR WELCOME! :p

 --
 Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com
 IvanMiljenovic.wordpress.com

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


Re: [Haskell-cafe] lists of arbitrary depth

2010-07-13 Thread Vo Minh Thu
2010/7/13 Ivan Lazar Miljenovic ivan.miljeno...@gmail.com:
 vadali shlomivak...@gmail.com writes:

 hello,
 iam really new to haskell,

 i want to define a function which takes as a parameter a list which can
 contain other lists, eg. [1,[2,3],[4,[5,6]]]

 how would i define a function that can iterate through the items so (in this
 example)
 iter1 = 1
 iter2 = [2,3]
 iter3 = [4,[5,6]]

 ?

 ( can i do that without using the Tree data type? )

 Well, that's what a tree is, so why not use a tree?

 Your only other option is to define your own tree-like structure:

 data MyTree a = Value a | SubTree [MyTree a]

Defining your own tree structure is better in this case as Data.Tree
store elements in each node, not just in the leaves.

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


Re: [Haskell-cafe] lists of arbitrary depth

2010-07-13 Thread Thomas Davie

On 13 Jul 2010, at 10:11, Shlomi Vaknin wrote:

 Thank you all for replying!
 
 I am really beginning my baby steps in this fascinating language, and was 
 just wondering if it was possible to naturally scan lists with arbitrary 
 lists (aka trees :) ).

Trees aren't lists, Trees are trees...  Here's how you create one*

data Tree a = Leaf
 | Branch a [Tree a]

This roughly says, a tree can be made up of two possible things... First, it 
could be a leaf, and secondly, it could be a branch with an element at it, and 
a list of subtrees.

Some example trees using this data type:

1) Leaf
2) Branch 5 []
3) Branch 5 [Leaf]
4) Branch 5 [Branch 10 [], Branch 20 [], Leaf, Branch 50 [Branch 10 [], Leaf]]

When you have really strong typing, you also have very well specified types.  
You don't just use a list as if it were a tree, you declare what a tree is.

Bob

* In this case an arbitrarily branching tree, we could ofc declare different 
forms of tree here.___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] ANNOUNCE: Haskell 2010 Report (final)

2010-07-13 Thread Simon Marlow

On 12/07/2010 22:12, John Meacham wrote:

On Mon, Jul 12, 2010 at 01:50:01PM +0100, Simon Marlow wrote:

Right.  I like the idea of packages being able to declare re-exported
modules, indeed I considered doing this in GHC (when we needed base3)
but decided not to mainly because we would still need PackageImports,
and once you have PackageImports you can implement re-exports using
that, albeit with more boilerplate.  The advantage of direct re-exports,
as you say, is that it avoids a conflict when the module is imported.
However, since some of the modules would conflict anyway, there didn't
seem to be much advantage in avoiding the conflict in some cases but not
others.


Well, a main useful case is that I can do -phaskell98 and -phaskell2010
at the same time. So I can make the default jhc behavior be the union of
the two languages easily.


That works in GHC too: the modules of those two packages don't overlap. 
 That is partly because we never moved Prelude from base to haskell98.


But suppose the Haskell 2010 Prelude had some differences from the 
Haskell 98 Prelude - then a direct re-export wouldn't work, and you'd be 
stuck with conflicts again.  So my main point is that while direct 
re-exports avoid conflicts sometimes, they're not a general solution, 
and eventually you run into the same problems again.  There are 
differences between several Haskell 2010 modules and the equivalent base 
modules, so you won't be able to use re-exports for those.



There is also some philosophy behind it. I don't like coupling things
that don't need to be coupled, such as the interface a library exports
and the place that interface is implemented.


I agree with the philosophy, but I don't understand how package 
re-exports are part of its implementation - the Haskell module system 
already lets you re-export entities and therefore decouple the 
implementation from the API.



I think the ability for a package to define an 'interface' built up from
other re-exported modules will be very useful going forward, I am not
sure how hard something like that would be to implement in ghc, but it
may be worth it in the future.


Isn't that what PackageImports lets you do?


Hmm.. maybe. Jhc doesn't have PackageImports, the idea being that you
re-export modules rather than importing them from a specific package and
exporting their interface.  So, it sort of shifts the effort from the

 interface makers to the implementors, as in, the Haskell 98 Prelude
 will actually have to be in a module called Compat.Haskell98.Prelude
 and just re-exported by the 'haskell98' and 'haskell2010' modules.

I don't think the difference is as fundamental as you make out.  In 
Haskell you can already write


  module A ( module B ) where
  import B

which is the essence of re-exporting a module, and preserves the 
interface/implementation separation.  Now suppose A and B are the same 
module name, from different packages.  To implement this re-export you 
can either


 (1) Use a package re-export (in JHC)
 (2) Somehow avoid A and B being the same, e.g. by having an
 intermediate like Compat.Haskell98.Prelude
 (3) Use PackageImports (in GHC)

the advantage of (1) is that you can have both packages in scope without 
a conflict, whereas in (2/3) the two modules can export different 
interfaces, while still separating the implementation from the 
interface.  I think of PackageImports as just an optimisation that lets 
you avoid the intermediate module in (2).


So again, my point is that in the general case the APIs diverge, so you 
don't get to do (1), or you only get to do it for some modules, which 
could be confusing for users.



In one
sense 'Compat.Haskell98' sort of acts as a package import, but it isn't
actually tied to a package, it just refers to the
Compat.Haskell98.Prelude in scope. I also have a large aversion to
allowing package names to infect source files carte blanche. It blurs
the line between the language itself and the environment the language
runs in. It may be neccesarry at some point, but I'll put it off until a
case comes up that makes it abundantly clear that it is needed.


I agree with your aversion to putting package names in the source code, 
which is why we don't advertise PackageImports as an extension that we 
expect end users to use, and we don't let you use version numbers.


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


Re: [Haskell-cafe] lists of arbitrary depth

2010-07-13 Thread Shlomi Vaknin
Thank you Bob,
your example clarified how actually using such data type would appear in
haskell. I naively thought it would be as simple as defining a regular list,
but i see it is slightly more strict than that. I appreciate your help!

Vadali

On Tue, Jul 13, 2010 at 11:18 AM, Thomas Davie tom.da...@gmail.com wrote:


 On 13 Jul 2010, at 10:11, Shlomi Vaknin wrote:

  Thank you all for replying!
 
  I am really beginning my baby steps in this fascinating language, and was
 just wondering if it was possible to naturally scan lists with arbitrary
 lists (aka trees :) ).

 Trees aren't lists, Trees are trees...  Here's how you create one*

 data Tree a = Leaf
 | Branch a [Tree a]

 This roughly says, a tree can be made up of two possible things... First,
 it could be a leaf, and secondly, it could be a branch with an element at
 it, and a list of subtrees.

 Some example trees using this data type:

 1) Leaf
 2) Branch 5 []
 3) Branch 5 [Leaf]
 4) Branch 5 [Branch 10 [], Branch 20 [], Leaf, Branch 50 [Branch 10 [],
 Leaf]]

 When you have really strong typing, you also have very well specified
 types.  You don't just use a list as if it were a tree, you declare what a
 tree is.

 Bob

 * In this case an arbitrarily branching tree, we could ofc declare
 different forms of tree here.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Please report any bug of gtk2hs-0.11.0!

2010-07-13 Thread Christian Maeder
Andy Stewart schrieb:
 Hi all,
 
 We plan to release bug fix version : gtk2hs-0.11.1
 
 Please report any bug of gtk2hs-0.11.0, we will fix it before release
 gtk2hs-0.11.1

I'm looking forward for this bug-fix release (since gtk2hs-0.11.0 did
not work for me).

Because I've almost missed this message I reply to
gtk2hs-us...@lists.sourceforge.net, too.

Christian

 
 We plan to add many new APIs in gtk2hs-0.12.0, 
 so gtk2hs-0.11.1 will be the last stable version with current APIs.
 
 Thanks for your help!
 
   -- Andy
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Finding zipper for custom tree

2010-07-13 Thread Sergey Mironov
2010/7/2 Heinrich Apfelmus apfel...@quantentunnel.de:
 Sergey Mironov wrote:

 Hello list!
 I am trying to understand zipper concept using papers like [1] and [2].
 Though main idea looks clear, I still have a problem in applying it for
 custom data types.

 Please help me with deriving Zipper-type from

 data DTree a = P | D [(a, DTree)]

 Looking in [1] ('Zippers via Differentiation' chapter) I tried to do
 the following:

 1. Find a DTreeF type which is a pattern functor ([2], chapter 2.1) of my
 DTree
 2. Write DTreeF in 'algebraic' form (using '+' and '*')
 3. Find DTreeF' - derivative of DTreeF
 4. Define my zipper type using list of DTreeF'

 These are the right steps.

 Step 1 likely ends with

 data DTreeF a x = P | D [(a,x)]

 [2] says that using this pattern functor one could build a fixed-point
 version of DTree:

 data Fix f = In {out :: (f (Fix f))}
 data DTreeFP = Fix DTreeF

 but seems that I have nothing to do with it right now.

 The fixed point is just another way to write  DTree .

    DTreeFP a = DTree a

 Step 2 is my main question:

 In [1] authors did it for binary tree:

 data Tree a = Leaf a | Bin (Tree a) (Tree a)

 data TreeF a x = Leaf a | Bin x x

 and thus

 TreeF = a + x * x

 TreeF' = x + x

 My DTree has inner list of tuples. How should I rewrite it in terms of
 '+' and '*' ?

 Ah, you can't write it in terms of only '+' and '*' because you also have
 the list type in there:

    DTreeF = 1 + List (a * x)
                 ^^ List involves a fixed point

 So, to find the derivate, you have to calculate the derivative of  List
  first:

    List' x = List x * List x

 and then you can use the chain rule to find  DTreeF .


 Regards,
 Heinrich Apfelmus

 --
 http://apfelmus.nfshost.com

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


Sorry for late answer. Luke, Heinrich - thank you very much for explanations.
I feel that I need more reading to get familiar with differentiation
of functors and chain rule. Could you suggest some books or papers?

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


Re: [Haskell-cafe] Re: Functional dependencies and Peano numbers

2010-07-13 Thread Brent Yorgey
On Sun, Jul 11, 2010 at 12:43:47AM +0200, Jose A. Ortega Ruiz wrote:
 On Sat, Jul 10 2010, wren ng thornton wrote:
 
 
 [...]
 
 
  Yes, you can add multiple dependencies. The syntax is to use , after
  the first |.
 
  While having eight parameters is surely a desperate need for
  refactoring, there are times when you'd want multiple dependencies.
  For example, you can say
 
  class F a b | a - b, b - a where...
 
  to express a bijective function on types (that is, for every pair of A
  and B, if you know one of them then you know what the other must be
  uniquely).
 
 I know i should read the relevant articles, but how would one express
 such a bijection using type families?

You would just create two type families, one for each direction of the
mapping:

  type family F1 a :: *
  type instance F1 Int = Bool
  type instance F1 ...

  type family F2 a :: *
  type instance F2 Bool = Int
  type instance F2 ...

Of course, this is not quite the same thing, since with the MPTC
version we are guaranteed to get a bijection, but there is nothing
forcing F1 and F2 to have anything to do with one another (for example
I could have written type instance F2 Char = Int).  But I don't know
whether this would make a difference in practice.

-Brent

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


Re: [Haskell-cafe] lambda calculus and equational logic

2010-07-13 Thread Brent Yorgey
On Wed, Jul 07, 2010 at 09:56:08AM +0100, Patrick Browne wrote:
 Hi,
 In Haskell what roles are played by 1)lambda calculus and 2) equational
 logic? Are these roles related?
 
 Hopefully this question can be answered at a level suitable for this forum.

Since no one else has responded I'll take a quick stab at answering,
and others can fill in more information as appropriate, or ask further
questions.

  1) In general, the lambda calculus is seen as foundational
 conceptual basis for functional programming: Haskell has
 anonymous lambda expressions, higher-order functions, and
 currying, all of which come directly from the lambda calculus.

 More specifically, GHC's core language is based on a variant of
 System F omega, which is a fancy version of the simply-typed
 lambda calculus with polymorphism and type constructors.  If you
 were to print out the core language code generated by GHC for
 some Haskell program, you would essentially see a bunch of lambda
 calculus expressions.

  2) Haskell is able to embrace equational logic because of its
 insistence on purity: in a Haskell program (leaving aside for the
 moment things like seq and unsafePerformIO) you can always
 replace equals by equals (where equality is the normal
 beta-equality for System F omega, plus definitional equality
 introduced by Haskell declarations) without changing the
 semantics of your program. So the story of an equational logic
 for System F omega and the story of evaluating Haskell programs
 are to a large extent the same story.  Coming up with equational
 logics corresponding to most imperative languages (or even a
 non-pure functional language like OCaml) is massively complicated
 by the need to keep track of an implicit state of the world due
 to the presence of side effects.

I am not sure what to say about their relationship.  Perhaps my above
answers have already shed some light on that.

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


Re: [Haskell-cafe] ByteString, zipWith', and rewrite rules

2010-07-13 Thread Henning Thielemann

Thomas M. DuBuisson wrote:

Comments on the zipWith' function inside of Data.ByteString say:

-- Rewrite rules
-- are used to automatically covert zipWith into zipWith' when a pack is
-- performed on the result of zipWith.

This is only true internally to Data.ByteString because the zipWith'
function could be inlined away by GHC once that module is compiled,
right?  If I want pack (zipWith xor bs1 bs2) to be efficient then I'll
have to either get zipWith' exported or write my own lower level
zipWith'?


As far as I know GHC prefers RULES to INLINE, but it's fragile.

You may check with -ddump-simpl-stat.

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


[Haskell-cafe] Marshalling

2010-07-13 Thread Phyx
Hello

I'm wondering if anyone ever benchmarked marshalling in Haskell/GHC. No
matter how much I optimize my Haskell code my program still seems to run
slow, which leads me to beleive that Marshalling is painfully slow.

Does anyone know a way I can test this and fix it?

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


Re: [Haskell-cafe] Marshalling

2010-07-13 Thread Magnus Therning
On Tue, Jul 13, 2010 at 13:29, Phyx loneti...@gmail.com wrote:
 Hello

 I'm wondering if anyone ever benchmarked marshalling in Haskell/GHC. No
 matter how much I optimize my Haskell code my program still seems to run
 slow, which leads me to beleive that Marshalling is painfully slow.

 Does anyone know a way I can test this and fix it?

What kind of marshalling are you referring to?

/M

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


Re: [Haskell-cafe] lambda calculus and equational logic

2010-07-13 Thread Ben Lippmeier

On 13/07/2010, at 20:47 , Brent Yorgey wrote:

 On Wed, Jul 07, 2010 at 09:56:08AM +0100, Patrick Browne wrote:
 Hi,
 In Haskell what roles are played by 1)lambda calculus and 2) equational
 logic? Are these roles related?
 
 Hopefully this question can be answered at a level suitable for this forum.
 
 Since no one else has responded I'll take a quick stab at answering,
 and others can fill in more information as appropriate, or ask further
 questions.
 
  2) Haskell is able to embrace equational logic because of its
 insistence on purity: in a Haskell program (leaving aside for the
 moment things like seq and unsafePerformIO) you can always
 replace equals by equals (where equality is the normal
 beta-equality for System F omega, plus definitional equality
 introduced by Haskell declarations) without changing the
 semantics of your program. So the story of an equational logic
 for System F omega and the story of evaluating Haskell programs
 are to a large extent the same story.

Replacing equals by equals usually doesn't change anything. 

What kind of equality do you use for  getChar :: IO Char ?


  Coming up with equational
 logics corresponding to most imperative languages (or even a
 non-pure functional language like OCaml) is massively complicated
 by the need to keep track of an implicit state of the world due
 to the presence of side effects.

By massively complicated you mean harder than the simplest case. Haskell's 
do-notation makes the state of the world implicit, and performing the 
desugaring makes it explicit again -- but then that state isn't really the 
state of the word...

Sorry or my heckling. You gave a fine answer, to the standard question. 
However, I propose mandating that all such questions asked on the 
haskell-beginners list are answered with Haskell's purity solves everything 
-- but  on haskell-cafe they should get Haskell's purity solves everything, 
but read Sabry's paper on What is a Purely Functional Language, because it's 
really more subtle than that.

Cheers,
Ben.


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


Re: [Haskell-cafe] lambda calculus and equational logic

2010-07-13 Thread Peter Gammie
Ben, comments from the peanut gallery:

On 13/07/2010, at 11:51 PM, Ben Lippmeier wrote:

 What kind of equality do you use for  getChar :: IO Char ?

Surely this is easy: getChar denotes a particular IO action, which is always 
the same thing (i.e. self-identical and distinct from all other IO actions).

 By massively complicated you mean harder than the simplest case. 
 Haskell's do-notation makes the state of the world implicit, and performing 
 the desugaring makes it explicit again -- but then that state isn't really 
 the state of the word...

... which tells you that the passing-the-world semantics is not a faithful 
model of I/O.

In the archives of this list there are many comments on exactly this topic. A 
couple of quick pointers:

- Wouter Swierstra wrote a paper on this.

http://www.cse.chalmers.se/~wouter/repos/IOSpec/index.html

- Resumptions are a better model:

http://www.haskell.org/pipermail/haskell-cafe/2003-August/004892.html

Intuitively the state monad used by GHC works because it only needs to track 
dependencies between I/O actions - there is no need for the compiler to impose 
a total order on everything going on in the world (taken to be all of the 
context that could influence the execution of the program). For interesting 
programs it cannot, anyway.

cheers
peter

-- 
http://peteg.org/

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


[Haskell-cafe] New FGL naming survey

2010-07-13 Thread Ivan Lazar Miljenovic
Whether or not the new FGL that Thomas Bereknyei and I are working on
should keep the name was a semi-hot issue when we first mentioned the
fact that we were working on a new version about a month ago.  As such,
I've created a survey here to try and find out what the Haskell
community overall thinks we should call it:
https://spreadsheets.google.com/viewform?formkey=dGpzMmFnUWY3Uktodk5wdHlLQk5kT1E6MA

More info can be found on the actual survey page.

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: The site has been exploited (again)

2010-07-13 Thread Mike Dillon
begin Gwern Branwen quotation:
 Ashley has made me admin; I've spent the last 1.5 hours deleting all
 the vandalism and indef blocking the accounts. I have Recent Changes
 in my RSS reader, so hopefully in the future there will be no greater
 than 24 hours delay before vandalism is dealt with. A MW upgrade will
 also help (eg. currently checkuser* seems to be unavailable).
 
 * http://www.mediawiki.org/wiki/Extension:CheckUser

Excellent!

Putting aside what I said earlier about protection, which doesn't really
work well with a single active admin, it may still be worth putting some
protection in place to avoid a non-bot account maliciously sticking
something like the goatse.cx pic on the home page of Haskell.org. The
options I know of for doing this are the Patrolled Edits feature and the
FlaggedRevs extension. Unfortunately, I don't think either of these can
be applied only to a limited set of pages because of the MediaWiki
team's asinine insistence that they'll never support per-page
authorization mechanism properly.

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


Re: [Haskell-cafe] Marshalling

2010-07-13 Thread Phyx
Marshalling large amount of data from and to C

http://phyx.pastebin.com/WXGBr1bX shows the code I use to do this (it's
autogenerated, so just looking at 1 block should be enough)

The tool is mine, so i can change the code it generates, but i would need to
know how to do it better first.

On Tue, Jul 13, 2010 at 3:30 PM, Magnus Therning mag...@therning.orgwrote:

  On Tue, Jul 13, 2010 at 13:29, Phyx loneti...@gmail.com wrote:
  Hello
 
  I'm wondering if anyone ever benchmarked marshalling in Haskell/GHC. No
  matter how much I optimize my Haskell code my program still seems to run
  slow, which leads me to beleive that Marshalling is painfully slow.
 
  Does anyone know a way I can test this and fix it?

 What kind of marshalling are you referring to?

 /M

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

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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: jhc 0.7.4

2010-07-13 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 7/12/10 22:29 , Richard O'Keefe wrote:
 On Jul 11, 2010, at 9:38 AM, wren ng thornton wrote:
 Generally OSX takes UTF16 to be the standard encoding (I don't recall if
 it's LE or BE), though UTF8 is supported almost everywhere. I haven't
 checked to see whether that would affect this particular task though.
 
 Mac OS X 10.5 came with a lot of locales, including a lot of
 UTF-8 ones.  Indeed, the default was a UTF-8 one.
 But it didn't come with *any* UTF-16 locales.
 (As tested by 'locale -a'.)

wren is half right:  at the level of Unixy APIs (and this includes anything
that goes on in a Terminal window and anything that you will be doing from
Haskell) you use UTF8, but OSX APIs --- that is, Carbon and Cocoa --- use
UTF16.  So for the purposes of ghc/jhc OSX is UTF8, but if someone wrote a
fully native Cocoa-based runtime it would use UTF16.  (Compare Win32 APIs
to mingw APIs; very similar situation.)

- -- 
brandon s. allbery [linux,solaris,freebsd,perl]  allb...@kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university  KF8NH
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkw8kXcACgkQIn7hlCsL25XMBwCghhWYpvyhhpG5L3tnOZQcJPIQ
h8oAnA5c5kCbrjtD5bMe/yAyw/BDUTAl
=p0QN
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Marshalling

2010-07-13 Thread Thomas DuBuisson
That code is effectively copying the data (thats what those peeks /
pokes do), so it stands to reason it would be slow by most performance
standards.  The reason ByteStrings are fast when used both by C and
Haskell is there is a zero-copy `useAsCString`.

Cheers,
Thomas

On Tue, Jul 13, 2010 at 7:49 AM, Phyx loneti...@gmail.com wrote:
 Marshalling large amount of data from and to C

 http://phyx.pastebin.com/WXGBr1bX shows the code I use to do this (it's
 autogenerated, so just looking at 1 block should be enough)

 The tool is mine, so i can change the code it generates, but i would need to
 know how to do it better first.

 On Tue, Jul 13, 2010 at 3:30 PM, Magnus Therning mag...@therning.org
 wrote:

 On Tue, Jul 13, 2010 at 13:29, Phyx loneti...@gmail.com wrote:
  Hello
 
  I'm wondering if anyone ever benchmarked marshalling in Haskell/GHC. No
  matter how much I optimize my Haskell code my program still seems to run
  slow, which leads me to beleive that Marshalling is painfully slow.
 
  Does anyone know a way I can test this and fix it?

 What kind of marshalling are you referring to?

 /M

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


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


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


Re: [Haskell-cafe] Marshalling

2010-07-13 Thread Phyx
I understand that part, but the strings are generated from SDocs, and So
unless internally SDoc doesn't use String then I'm afraid there's nothing I
can do about that :/

Or rather, Is there a way to efficiently make CWStrings from SDocs?

Regards,
Phyx

On Tue, Jul 13, 2010 at 6:56 PM, Thomas DuBuisson 
thomas.dubuis...@gmail.com wrote:

 That code is effectively copying the data (thats what those peeks /
 pokes do), so it stands to reason it would be slow by most performance
 standards.  The reason ByteStrings are fast when used both by C and
 Haskell is there is a zero-copy `useAsCString`.

 Cheers,
 Thomas

 On Tue, Jul 13, 2010 at 7:49 AM, Phyx loneti...@gmail.com wrote:
  Marshalling large amount of data from and to C
 
  http://phyx.pastebin.com/WXGBr1bX shows the code I use to do this (it's
  autogenerated, so just looking at 1 block should be enough)
 
  The tool is mine, so i can change the code it generates, but i would need
 to
  know how to do it better first.
 
  On Tue, Jul 13, 2010 at 3:30 PM, Magnus Therning mag...@therning.org
  wrote:
 
  On Tue, Jul 13, 2010 at 13:29, Phyx loneti...@gmail.com wrote:
   Hello
  
   I'm wondering if anyone ever benchmarked marshalling in Haskell/GHC.
 No
   matter how much I optimize my Haskell code my program still seems to
 run
   slow, which leads me to beleive that Marshalling is painfully slow.
  
   Does anyone know a way I can test this and fix it?
 
  What kind of marshalling are you referring to?
 
  /M
 
  --
  Magnus Therning(OpenPGP: 0xAB4DFBA4)
  magnus@therning.org  Jabber: magnus@therning.org
  http://therning.org/magnus identi.ca|twitter: magthe
 
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 

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


Re: [Haskell-cafe] Comments on Haskell 2010 Report

2010-07-13 Thread Nick Bowler
On 16:21 Fri 09 Jul , John Meacham wrote:
 I would think it is a typo in the report. Every language out there seems
 to think 0**0 is 1 and 0**y | y /= 0 is 0. I am not sure whether it is
 mandated by the IEEE standard but a quick review doesn't say they should
 be undefined (and the report mentions all the operations with undefined
 results)

IEEE 754 has three different power operations.  They are recommended
operations, which means that supporting them is optional.

pown only allows integral exponents, and the standard says the following:

pown (x, 0) is 1 for any x (even a zero, quiet NaN, or infinity)

pow handles integral exponents as a special case, and is similar:

pow (x, ±0) is 1 for any x (even a zero, quiet NaN, or infinity)

powr is defined as exp(y*log(x)).

powr (±0, ±0) signals the invalid operation exception
[NB: this means that the operation returns a quiet NaN].

In C, the pow function corresponds to the pow operation here,
assuming the implementation conforms to annex F of the standard (an
optional feature).
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: The site has been exploited (again)

2010-07-13 Thread Don Stewart
gwern0:
 
 Ashley has made me admin; I've spent the last 1.5 hours deleting all
 the vandalism and indef blocking the accounts. I have Recent Changes
 in my RSS reader, so hopefully in the future there will be no greater
 than 24 hours delay before vandalism is dealt with. A MW upgrade will
 also help (eg. currently checkuser* seems to be unavailable).
 
 * http://www.mediawiki.org/wiki/Extension:CheckUser

Thank you so much, Gwern!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] AngloHaskell 2010

2010-07-13 Thread Derek Wright
Are you interested in AngloHaskell 2010?

AngloHaskell is a gathering of all people Haskell-related from beginners to
seasoned hackers. Previously it has been held in Cambridge (three times) and
London (once).

Last year I volunteered to organise it but I want know when you can attend.
Traditionally it is the first Friday and Saturday in August, which this year
is the 6th and 7th August. But we may only have enough time to organise one
day so the question for you is:

Q) Which day is better for you? Friday, Saturday or either?

I am looking for venues in London but if you can suggest or offer a venue
then let me know.

As well as attendees we are looking for talks on all and any Haskell related
subjects. There is a section on the wiki page
http://www.haskell.org/haskellwiki/AngloHaskell/2010 for talks. Please go
ahead and add your talk to it.

Let me know by email, the wiki or the #anglohaskell IRC channel.

I planning to have the venue confirmed this week and then a full
announcement will be made.

Thanks,

Derek.



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


[Haskell-cafe] library for objective-j?

2010-07-13 Thread Günther Schmidt

Hi all,

is there a haskell library for generating Objective-J?

Günther

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


Re: [Haskell-cafe] lambda calculus and equational logic

2010-07-13 Thread Patrick Browne

 In Haskell what roles are played by 1)lambda calculus and 2) equational
 logic? Are these roles related?


Hi,
Thanks for your clear and helpful responses.
I am aware that this question can lead to into very deep water.
I am comparing Haskell with languages based on equational logic (EL)
(e.g. Maude/CafeOBJ, lets call them ELLs).  I need to identify the
fundamental distinction between the semantics of ELLs and Haskell. The
focus of my original question was just the purely functional, side
effect free, part of Haskell.

Semantics can be understood under three headings:
*Denotational Semantics; is a model theoretical approach which describes
a program in terms of precise mathematical objects (e.g. sets and
functions) which provide meaning to a program text.
*Operational semantics: provides a technique for computing a result, ELs
use term rewriting systems for their operational semantics.
*Proof  theoretic semantic:  syntactically derivable proofs, can use the
rules of a logic

The relationship between the denotational and the proof theoretic
semantic is important for soundness and completeness. Which was sort of
 behind my original question.


Would it be fair to say
1)Lambda calculus provides the operational semantics for Haskell

2)Maybe equational logic provides the denotational semantics.

3)I am not sure of proof theoretic semantic for Haskell.
  The Curry-Howard correspondence is a proof theoretic view but only at
  type level.

Obviously, the last three points are represent my efforts to address
this question. Hopefully the café can comment on the accuracy of these
points.

Thanks,
Pat


This message has been scanned for content and viruses by the DIT Information 
Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] library for objective-j?

2010-07-13 Thread Jason Dagit
2010/7/13 Günther Schmidt gue.schm...@web.de

 Hi all,

 is there a haskell library for generating Objective-J?


http://www.google.co.uk/search?hl=enas_sitesearch=hackage.haskell.org/packageas_q=object-j

Hackage upload or it didn't happen!

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


Re: [Haskell-cafe] library for objective-j?

2010-07-13 Thread Günther Schmidt

Jason dearest,

http://hoc.sourceforge.net/ did happen but isn't on hackage,
WASH did happen but isn't on hackage ...

and I presume quite a few other goodies didn't make it to hackage either.

So I was hoping I'd finally be admitted to the inner haskellers circle 
where the dark arts are practized and the secrets are revealed that mere 
newbies don't even know about. :)



Günther


Am 13.07.10 22:28, schrieb Jason Dagit:

2010/7/13 Günther Schmidtgue.schm...@web.de


Hi all,

is there a haskell library for generating Objective-J?



http://www.google.co.uk/search?hl=enas_sitesearch=hackage.haskell.org/packageas_q=object-j

Hackage upload or it didn't happen!

Jason



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


[Haskell-cafe] [Newbie] What to improve in my code

2010-07-13 Thread Frank1981

First of all: I'm not sure if this question is allowed here. If not, I
apologize

I'm trying to solve the following problem: For each word in a text find the
number of occurences for each unique word in the text.

i've come up with the following steps to solve this:
 * remove all punctuation except for whitespace and make the text lowercase
 * find all unique words in the text
 * for each unique word, count the number of occurences.

This has resulted in the following code:
removePunctuation :: [Char] - [Char]
removePunctuation str = filter (\c - elem c (['a'..'z'] ++ ['A'..'Z'] ++
['\t', ' ', '\n'])) str


process :: [Char] - [String]
process str = words (map toLower (removePunctuation str))

unique :: (Eq a) = [a] - [a]
unique [] = []
unique (x:xs) = [x] ++ unique (filter (\s - x /= s) xs)

occurenceCount :: (Eq a) = a - [a] - Int
occurenceCount _ [] = 0
occurenceCount x (y:ys)
| x == y = 1 + occurenceCount x ys
| otherwise = occurenceCount x ys

occurenceCount' :: [String] - [String] - [(String, Int)]
occurenceCount' [] _ = [(, 0)]
occurenceCount' (u:us) xs = [(u, occurenceCount u xs)] ++ occurenceCount' us
xs

Please remember i've only been playing with Haskell for three afternoons now
and i'm happy that the above code is working correctly.

However i've got three questions:
1) occurenceCount' [] _ = [(, 0)] is plain ugly and also adds a useless
tuple to the end result. Is there a better way to solve this?
2) I'm forcing elements into a singleton list on two occasions, both in my
unique function and in my occurenceCount' function. Once again this seems
ugly and I'm wondering if there is a better solution.
3) The whole process as i'm doing it now feels pretty imperatively (been
working for years as a Java / PHP programmer). I've got this feeling that
the occurenceCount' function could be implemented using a mapping function.
What ways are there to make this more functional?
  
-- 
View this message in context: 
http://old.nabble.com/-Newbie--What-to-improve-in-my-code-tp29156025p29156025.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] library for objective-j?

2010-07-13 Thread Jason Dagit
2010/7/13 Günther Schmidt gue.schm...@web.de

 Jason dearest,

 http://hoc.sourceforge.net/ did happen but isn't on hackage,


http://code.google.com/p/hoc/issues/detail?id=26#c0


 WASH did happen but isn't on hackage ...


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


[Haskell-cafe] Collecting MonadError errors generically

2010-07-13 Thread Leon Grynszpan
Hello,

This is my first post to the Haskell Café, and I'm hoping the issue
I'm tackling here isn't one that's been thoroughly explored elsewhere.
If that's the case, I'll apologize in advance for my insufficient
google chops. Otherwise, here goes...

I do a lot of work within the error monad. Having read Eric Kidd's
blog on error reporting in Haskell
(http://www.randomhacks.net/articles/2007/03/10/haskell-8-ways-to-report-errors),
I'm always a bit paranoid about dealing with errors in the most
generic, flexible way possible. As a result, a lot of the functions I
use that could result in errors have signatures along these lines:

couldThrowError :: (Error e, MonadError e m) = t1 - t2 - m t3

The way I figure it, this means that I can use these functions within
any particular MonadError, which keeps me happy if I decide to change
implementations at any particular point during development.

Usually, I use these couldThrowError functions in a standard do block.
Something along the lines of:

couldThrowError :: (Error e, MonadError e m) = t1 - t2 - m t3
couldThrowError = do x - processWithPossibleError t1
                                y - processWithPossibleError t2
                                ...
                                return (z :: t3)

Things stay generic at this level. I can still choose any MonadError
implementation I want, and if any of the computations in the do block
throws an Error, the whole function short-circuits.

Often enough, however, I don't want this kind of short-circuiting
behavior. What I want, instead, is to run a whole bunch of
computations that may throw errors. If there are any errors, I want to
collect them all into one big master error. If not, I want a list of
results. Here's an example of usage:

couldThrowError :: (Error e, MonadError e m) = t1 - m t2
getParams :: (Error e, MonadError e m) = [t1] -- m [t2]
getParams = groupErrors . map couldThrowError

I found it pretty easy to implement groupErrors for Either String:

groupErrors :: (Error e, MonadError e m) = [Either String a] - m [a]
groupErrors eithers = case partitionEithers eithers of
                                       ([], xs) - return xs
                                       (es,  _) - strError $ unlines es

The problem, though, is that running this function now causes type
inference to provide Either String as my MonadError implementation.
If any of the potential error sources are dealing with a different
concrete implementation, I'm stuck! It would be nice if I could stay
generic. I made an effort at this that you can see below, but it
strikes me as very awkward.

collectErrors :: (Monoid e, Error e, MonadError e m) = m a - m [a] - m [a]
collectErrors m1 m2 =
 do m1r - (m1 `catchError` (\e1 -
               (m2 `catchError` (\e2 -
                   throwError $ mappend e1 e2)) 
               throwError e1))
    m2r - m2
    return $ m1r : m2r
groupErrors' :: (Monoid e, Error e, MonadError e m) = [m a] - m [a]
groupErrors' = foldr collectErrors (return [])

As you can see, I now require an error type that implements monoid. An
example I've tested is:

newtype ErrorString = ES String
    deriving (Read, Show, Eq, Ord, Error)
instance Monoid ErrorString where
    mempty                  = ES 
    mappend (ES s1) (ES s2) = ES $ s1 `mappend` \n `mappend` s2

This seems to work, but something strikes me as being very hackish
here. Maybe it's just that collectErrors looks very ugly, and in
Haskell my intuition tells me that what looks ugly on the surface is
often ugly down below. I suspect that I might really not be
approaching this problem the right way, but after a lot of time spent
wrestling with it, I'm eager to read your suggestions. Is there a
better way to do groupErrors, or should I be looking at an entirely
different philosophy?

Thanks,

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


Re: [Haskell-cafe] [Newbie] What to improve in my code

2010-07-13 Thread Daniel Fischer
On Tuesday 13 July 2010 23:49:45, Frank1981 wrote:
 First of all: I'm not sure if this question is allowed here. If not, I
 apologize

 I'm trying to solve the following problem: For each word in a text find
 the number of occurences for each unique word in the text.

 i've come up with the following steps to solve this:
  * remove all punctuation except for whitespace and make the text
 lowercase * find all unique words in the text
  * for each unique word, count the number of occurences.

 This has resulted in the following code:
 removePunctuation :: [Char] - [Char]
 removePunctuation str = filter (\c - elem c (['a'..'z'] ++ ['A'..'Z']
 ++ ['\t', ' ', '\n'])) str

Depending on your criteria, maybe

import Data.Char

removePunctuation = filter (\c - isAlpha c || isSpace c)

is better


 process :: [Char] - [String]
 process str = words (map toLower (removePunctuation str))

Or perhaps

process = map (fiter isLower) . words . map toLower


 unique :: (Eq a) = [a] - [a]
 unique [] = []
 unique (x:xs) = [x] ++ unique (filter (\s - x /= s) xs)

import Data.List

unique = nub

but it's not particularly efficient.
If you don't need to keep the order of first occurrence and have an Ord 
instance, you could take

unique' = map head . group . sort

or

import qualified Data.Set as Set

unique'' = Set.toList . Set.fromList


 occurenceCount :: (Eq a) = a - [a] - Int
 occurenceCount _ [] = 0
 occurenceCount x (y:ys)

   | x == y = 1 + occurenceCount x ys
   | otherwise = occurenceCount x ys

occurrenceCount a xs = length (filter (== a) xs)

or

occurrenceCount a = length . filter (== a)


 occurenceCount' :: [String] - [String] - [(String, Int)]
 occurenceCount' [] _ = [(, 0)]

why not occurrenceCount' [] _ = [] ?

 occurenceCount' (u:us) xs = [(u, occurenceCount u xs)] ++
 occurenceCount' us xs

But it can be done shorter:

import qualified Data.Map as Map
import Data.List

occurrenceCount'' :: Ord a = [a] - [(a,Int)]
occurrenceCount'' xs = Map.toList $ 
  foldl' (\mp x - Map.insertWith' (+) x 1 mp) Map.empty xs

No need to get the unique elements up front.


 Please remember i've only been playing with Haskell for three afternoons
 now and i'm happy that the above code is working correctly.

 However i've got three questions:
 1) occurenceCount' [] _ = [(, 0)] is plain ugly and also adds a
 useless tuple to the end result. Is there a better way to solve this?
 2) I'm forcing elements into a singleton list on two occasions, both in
 my unique function and in my occurenceCount' function. Once again this
 seems ugly and I'm wondering if there is a better solution.

Use (:), e.g.

unique (x:xs) = x : unique (filter (/= x) xs)

 3) The whole process as i'm doing it now feels pretty imperatively (been
 working for years as a Java / PHP programmer). I've got this feeling
 that the occurenceCount' function could be implemented using a mapping
 function. What ways are there to make this more functional?

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


Re: [Haskell-cafe] Collecting MonadError errors generically

2010-07-13 Thread Gregory Crosswhite
Leon,

In order to avoid the short-circuiting behaviour, it might help you to
work in terms of Applicatives instead of Monads.  For example, in my
error-message package I have the following instance:

instance (Monoid e) = Applicative (Either e) where
pure = Right
(*) (Left error2) (Left error1) = Left (error1 `mappend` error2)
(*) (Left error) _ = Left error
(*) _ (Left error) = Left error
(*) (Right function) (Right argument) = Right (function argument)

This allows me to write

liftA2 (,) calculation1 calculation2

so that both calculations are always run and the errors are collected
together.  This contrasts with

liftM2 (,) calculation1 calculation2

which halts if calculation1 and doesn't even bother to run calculation2.

Cheers,
Greg

On 07/13/10 15:08, Leon Grynszpan wrote:
 Hello,

 This is my first post to the Haskell Café, and I'm hoping the issue
 I'm tackling here isn't one that's been thoroughly explored elsewhere.
 If that's the case, I'll apologize in advance for my insufficient
 google chops. Otherwise, here goes...

 I do a lot of work within the error monad. Having read Eric Kidd's
 blog on error reporting in Haskell
 (http://www.randomhacks.net/articles/2007/03/10/haskell-8-ways-to-report-errors),
 I'm always a bit paranoid about dealing with errors in the most
 generic, flexible way possible. As a result, a lot of the functions I
 use that could result in errors have signatures along these lines:

 couldThrowError :: (Error e, MonadError e m) = t1 - t2 - m t3

 The way I figure it, this means that I can use these functions within
 any particular MonadError, which keeps me happy if I decide to change
 implementations at any particular point during development.

 Usually, I use these couldThrowError functions in a standard do block.
 Something along the lines of:

 couldThrowError :: (Error e, MonadError e m) = t1 - t2 - m t3
 couldThrowError = do x - processWithPossibleError t1
 y - processWithPossibleError t2
 ...
 return (z :: t3)

 Things stay generic at this level. I can still choose any MonadError
 implementation I want, and if any of the computations in the do block
 throws an Error, the whole function short-circuits.

 Often enough, however, I don't want this kind of short-circuiting
 behavior. What I want, instead, is to run a whole bunch of
 computations that may throw errors. If there are any errors, I want to
 collect them all into one big master error. If not, I want a list of
 results. Here's an example of usage:

 couldThrowError :: (Error e, MonadError e m) = t1 - m t2
 getParams :: (Error e, MonadError e m) = [t1] -- m [t2]
 getParams = groupErrors . map couldThrowError

 I found it pretty easy to implement groupErrors for Either String:

 groupErrors :: (Error e, MonadError e m) = [Either String a] - m [a]
 groupErrors eithers = case partitionEithers eithers of
([], xs) - return xs
(es,  _) - strError $ unlines es

 The problem, though, is that running this function now causes type
 inference to provide Either String as my MonadError implementation.
 If any of the potential error sources are dealing with a different
 concrete implementation, I'm stuck! It would be nice if I could stay
 generic. I made an effort at this that you can see below, but it
 strikes me as very awkward.

 collectErrors :: (Monoid e, Error e, MonadError e m) = m a - m [a] - m [a]
 collectErrors m1 m2 =
  do m1r - (m1 `catchError` (\e1 -
(m2 `catchError` (\e2 -
throwError $ mappend e1 e2)) 
throwError e1))
 m2r - m2
 return $ m1r : m2r
 groupErrors' :: (Monoid e, Error e, MonadError e m) = [m a] - m [a]
 groupErrors' = foldr collectErrors (return [])

 As you can see, I now require an error type that implements monoid. An
 example I've tested is:

 newtype ErrorString = ES String
 deriving (Read, Show, Eq, Ord, Error)
 instance Monoid ErrorString where
 mempty  = ES 
 mappend (ES s1) (ES s2) = ES $ s1 `mappend` \n `mappend` s2

 This seems to work, but something strikes me as being very hackish
 here. Maybe it's just that collectErrors looks very ugly, and in
 Haskell my intuition tells me that what looks ugly on the surface is
 often ugly down below. I suspect that I might really not be
 approaching this problem the right way, but after a lot of time spent
 wrestling with it, I'm eager to read your suggestions. Is there a
 better way to do groupErrors, or should I be looking at an entirely
 different philosophy?

 Thanks,

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

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org

Re: [Haskell-cafe] lists of arbitrary depth

2010-07-13 Thread Richard O'Keefe


On Jul 13, 2010, at 9:00 PM, Christopher Done wrote:


On 13 July 2010 10:58, vadali shlomivak...@gmail.com wrote:\


i want to define a function which takes as a parameter a list which  
can

contain other lists, eg. [1,[2,3],[4,[5,6]]]


What would the type of a list like that be?

What you _can_ do is
data List_Or t = Item t | List [List_Or t]
 deriving (Eq, Ord, Show)
and have a list like
ell :: List_Or Int
ell = List [Item 1, List [Item 2, Item 3], List [Item 4,
  List [Item 5, Item 6]]]

how would i define a function that can iterate through the items so  
(in this

example)
iter1 = 1
iter2 = [2,3]
iter3 = [4,[5,6]]



Then you can write functions like
iter n (List x) = head (drop (n-1) x)
with examples
*Main iter 1 ell
Item 1
*Main iter 2 ell
List [Item 2,Item 3]
*Main iter 3 ell
List [Item 4,List [Item 5,Item 6]]


( can i do that without using the Tree data type? )


This basically _is_ a tree data type, even if not THE Tree
data type.  That's because nested lists are trees.




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


Re: [Haskell-cafe] lambda calculus and equational logic

2010-07-13 Thread Richard O'Keefe


On Jul 14, 2010, at 1:51 AM, Ben Lippmeier wrote:

Replacing equals by equals usually doesn't change anything.

What kind of equality do you use for  getChar :: IO Char ?


The usual one:  getChar = getChar.  It's a pure value.
If I find [getChar,getChar] in a program, I can safely
replace it by let g = getChar in [g,g].


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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: jhc 0.7.4

2010-07-13 Thread Richard O'Keefe


wren is half right:  at the level of Unixy APIs (and this includes  
anything
that goes on in a Terminal window and anything that you will be  
doing from
Haskell) you use UTF8, but OSX APIs --- that is, Carbon and Cocoa  
--- use
UTF16.  So for the purposes of ghc/jhc OSX is UTF8, but if someone  
wrote a
fully native Cocoa-based runtime it would use UTF16.  (Compare  
Win32 APIs

to mingw APIs; very similar situation.)


I guess the question here is what it _means_ to say that the standard
encoding is UTF-8 or UTF-16 or anything else.  I took it to be an
*external* property:  what is the expected/best supported encoding
for *user* data.  By that criterion, the only standard encoding for
Mac OS X 5 would appear to be UTF-8; it did not come with any support
for *user* data in UTF-16.  If the question means what is the encoding
used by the kernel, or by the native interfaces to the kernel, that
gets a different answer.

I've now lost track:  what did the original poster mean?


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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Haskell 2010 Report (final)

2010-07-13 Thread John Meacham
On Tue, Jul 13, 2010 at 10:24:00AM +0100, Simon Marlow wrote:
 Well, a main useful case is that I can do -phaskell98 and -phaskell2010
 at the same time. So I can make the default jhc behavior be the union of
 the two languages easily.

 That works in GHC too: the modules of those two packages don't overlap.  
 That is partly because we never moved Prelude from base to haskell98.

But don't you still have to have things directly declare they depend on
'base' then in order to get 'Prelude'? The extra dependency on the
implementation specific 'base' because you want both haskell98 and
haskell2010 is what I am trying to avoid.

 But suppose the Haskell 2010 Prelude had some differences from the  
 Haskell 98 Prelude - then a direct re-export wouldn't work, and you'd be  
 stuck with conflicts again.  So my main point is that while direct  
 re-exports avoid conflicts sometimes, they're not a general solution,  
 and eventually you run into the same problems again.  There are  
 differences between several Haskell 2010 modules and the equivalent base  
 modules, so you won't be able to use re-exports for those.

Yeah, jhc really doesn't have a good solution for that. 

Something I was thinking about was 'union' modules, like, if you include
two libraries that both export Data.List, you get the union of both of
what they export with conflicts being reported lazily (though, instance
conflicts will likely have to be reported strictly). It may help in some
cases, but again, is not a general solution. (and I can imagine it would
be confusing if it happened when people wern't expecting it...)

 Hmm.. maybe. Jhc doesn't have PackageImports, the idea being that you
 re-export modules rather than importing them from a specific package and
 exporting their interface.  So, it sort of shifts the effort from the
  interface makers to the implementors, as in, the Haskell 98 Prelude
  will actually have to be in a module called Compat.Haskell98.Prelude
  and just re-exported by the 'haskell98' and 'haskell2010' modules.

 I don't think the difference is as fundamental as you make out.  In  
 Haskell you can already write

Yeah, I don't think they are really that different in capabilities.
Though, Jhc currently has a restriction that module names (real modules,
not re-exported ones) cannot ever conflict, even if hidden, so there is
a big difference in expressibility at the moment, but that is mainly due
to what I consider a bug in jhc, or a misfeature at best.

John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: New FGL naming survey

2010-07-13 Thread Ivan Miljenovic
Thank you for all the people who have voted; we so far have 42 results
in about 12 hours.

Some indication of the results so far:

* 62% prefer inductive-graphs

* 62% have indicated that they use fgl or do some graph-related stuff
(no correlation, just an interesting coincidence; I have not as yet
done the number crunching to tell what the most popular name is for
people that actually use fgl or other graph stuff).

* Someone stated that ponies smell sweaty... not sure how that's
relevant, but OK.

* At least two people prefer the new name as it isn't an acronym (one
because acronyms aren't needed and the term functional is redundant,
the other because the term graph isn't directly in the package
name).

* Martin Erwig himself said that he thinks we should keep using the name fgl.

So, keep the votes coming in (I actually didn't expect this many already)!

On 14 July 2010 00:24, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote:
 Whether or not the new FGL that Thomas Bereknyei and I are working on
 should keep the name was a semi-hot issue when we first mentioned the
 fact that we were working on a new version about a month ago.  As such,
 I've created a survey here to try and find out what the Haskell
 community overall thinks we should call it:
 https://spreadsheets.google.com/viewform?formkey=dGpzMmFnUWY3Uktodk5wdHlLQk5kT1E6MA

 More info can be found on the actual survey page.

 --
 Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com
 IvanMiljenovic.wordpress.com




-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Please report any bug of gtk2hs-0.11.0!

2010-07-13 Thread briand
Short version of this post:

Looks like the intsall depends on alex and that dependencies doesn't
appear to be handled, i.e. I had to install alex before proceeding.

why do is it called gtk2hs if you are actually installing package
gtk ;-)

Where's the demo directory ?!

Moral of the story: don't forget to install -dev version of the
necessary libraries. For me that was libpango1.0-dev, libgtk2.0-dev and
libglib2.0-dev.

The long version:

I have a debian system and I expect the problems I found to be
relatively common.  Hope this is useful.

First I found that I needed package alex.

then i was able to 

  cabal install gtk2hs-buildtools

however

  cabal install gtk

didn't work:

Configuring glib-0.11.0...
setup: The pkg-config package glib-2.0 is required but it could not be
found. cabal: Error: some packages failed to install:
gio-0.11.0 depends on glib-0.11.0 which failed to install.
glib-0.11.0 failed during the configure step. The exception was:
ExitFailure 1
gtk-0.11.0 depends on glib-0.11.0 which failed to install.
pango-0.11.0 depends on glib-0.11.0 which failed to install.

  cabal install glib

Configuring glib-0.11.0...
setup: The pkg-config package glib-2.0 is required but it could not be
found. cabal: Error: some packages failed to install:
glib-0.11.0 failed during the configure step. The exception was:
ExitFailure 1

now it's not obvious to me at this point if it's referencing a cabal
package glib-2.0 or the unix libs.  But I'm going to guess it's
actually the unix libs.

I do have the unix libs installed :

ii  libglib2.0-0
2.24.1-1   The GLib library of C routines

However I remembered that annoying little thing that there is always
those darn -dev versions of the lib that you need when you actually
want to compile against libraries. So I installed it and got farther
along, crashing on pango.

Turns out it's the same problem.  So install libpango1.0-dev and
continue...

Stopped again on gtk+, aka gtk libgtk2.0-dev.  Installed it, and
trudged on.

I noticed that the install process stays at this point for a long
time:

Preprocessing library gtk-0.11.0...

But it does eventually continue, and it even completes successfully !

Strangely, at this point, I find that I don't know that I actually have
gtk2hs installed.  I know that this sound kinda dumb, but I just did
cabal install gtk, right ?  I immediately tried cabal install
gtk2hs, which said no such library, and realized that gtk was it :-)

So I'd like to run a demo to make sure things are installed properly.

Running the demos.
--

To get started, you can compile and run one of the programs that reside
in the demo/ directory in the respective packages. For example:

~/gtk2hs/gtk/demo/hello:$ make


But after the installation the demo directory is nowhere to be found.
Do you need to pull it in with darcs ??


 Brian

On Tue, 13 Jul 2010 11:42:26 +0200
Christian Maeder christian.mae...@dfki.de wrote:

 Andy Stewart schrieb:
  Hi all,
  
  We plan to release bug fix version : gtk2hs-0.11.1
  
  Please report any bug of gtk2hs-0.11.0, we will fix it before
  release gtk2hs-0.11.1
 
 I'm looking forward for this bug-fix release (since gtk2hs-0.11.0 did
 not work for me).
 
 Because I've almost missed this message I reply to
 gtk2hs-us...@lists.sourceforge.net, too.
 
 Christian
 
  
  We plan to add many new APIs in gtk2hs-0.12.0, 
  so gtk2hs-0.11.1 will be the last stable version with current APIs.
  
  Thanks for your help!
  
-- Andy
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


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


Re: [Haskell-cafe] Re: Please report any bug of gtk2hs-0.11.0!

2010-07-13 Thread Ivan Miljenovic
On 14 July 2010 14:52,  bri...@aracnet.com wrote:
 Short version of this post:

 Looks like the intsall depends on alex and that dependencies doesn't
 appear to be handled, i.e. I had to install alex before proceeding.

Yes, cabal-install isn't able to cope with the build-tools dependencies.

 why do is it called gtk2hs if you are actually installing package
 gtk ;-)

The overall meta-project is called gtk2hs, and all these libraries
used to come together in one big package called gtk2hs.

 Where's the demo directory ?!

Does it say there's one?

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe