Re: [Haskell-cafe] Stack ADT?

2010-02-05 Thread Andrew Wagner
What's going on is that data structures in Haskell are immutable. Thus,
when you call push on a stack, you get a new stack with the new element
pushed onto it, and the original stack is left un-touched.

On Fri, Feb 5, 2010 at 10:56 AM, michael rice nowg...@yahoo.com wrote:

 Not using Stack for anything, just trying to understand how things can be
 done in Haskell.

 To that end...

 What's going on here? I'm not even calling function POP.

 Michael

 ==

 module Data.Stack (Stack, emptyStack, isEmptyStack, push, pop, top) where

 newtype Stack a = Stack [a]

 emptyStack = Stack []
 isEmptyStack (Stack xs) = null xs
 push x (Stack xs) = Stack (x:xs)
 pop (Stack (_:xs)) = Stack xs
 top (Stack (x:_)) = x

 ==

 [mich...@localhost ~]$ ghci Stack.hs
 GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
 Loading package ghc-prim ... linking ... done.
 Loading package integer ... linking ... done.
 Loading package base ... linking ... done.
 [1 of 1] Compiling Data.Stack   ( Stack.hs, interpreted )
 Ok, modules loaded: Data.Stack.
 *Data.Stack let s1 = emptyStack
 *Data.Stack top (push 1 s1)
 1
 *Data.Stack top (push 2 s1)
 2
 *Data.Stack top (push 3 s1)
 3
 *Data.Stack let s2 = pop s1
 *Data.Stack top s2
 *** Exception: Stack.hs:8:0-28: Non-exhaustive patterns in function pop

 *Data.Stack




 --- On *Fri, 2/5/10, Casey Hawthorne cas...@istar.ca* wrote:


 From: Casey Hawthorne cas...@istar.ca
 Subject: Re: [Haskell-cafe] Stack ADT?
 To: haskell-cafe@haskell.org
 Date: Friday, February 5, 2010, 10:36 AM

 You could also implement stacks with mutable data structures, e.g.
 STArray, etc.

 What do you want to use a stack ADT for?

 Usually stacks are discussed for pedagogical purposes but usually
 recursion is used if you need a stack like operation.
 --
 Regards,
 Casey
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org http://mc/compose?to=haskell-c...@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] Pattern matching does not work like this?

2009-07-15 Thread Andrew Wagner
Err, technically, aren't functions and constructors mutually exclusive? So
if something is a function, it's, by definition, not a constructor?

On Wed, Jul 15, 2009 at 6:25 AM, Eugene Kirpichov ekirpic...@gmail.comwrote:

 Technically, the reason is not that (++) is a function, but that it is
 not a constructor of the [] type.

 And, not only is it not a constructor, but it also *can't* be one,
 because the main characteristic of pattern matching in Haskell is that
 it is (contrary to Prolog's unification) unambiguous (unambiguity of
 constructors is guaranteed by the semantics of Haskell's algebraic
 datatypes).

 If ++ could be pattern matched, what should have been the result of
 let (x++y)=[1,2,3] in (x,y)?

 2009/7/15 minh thu not...@gmail.com:
  2009/7/15 Magicloud Magiclouds magicloud.magiclo...@gmail.com:
  Hi,
   I do not notice this before. fun ([0, 1] ++ xs) = .. in my code
  could not be compiled, parse error.
 
  ++ is a function; you can't pattern-match on that.
 
  Cheers,
  Thu
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 



 --
 Eugene Kirpichov
 Web IR developer, market.yandex.ru
 ___
 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] What to say about Haskell?

2009-07-14 Thread Andrew Wagner
http://www.haskell.org/haskellwiki/Tying_the_Knot would seem to be relevant.

On Tue, Jul 14, 2009 at 9:55 AM, Cristiano Paris fr...@theshire.org wrote:


 I would like to know them.

 I'm looking for small snippets of code that are elegant when written
 in Haskell (which is lazy by default) but not in other languages
 supporting some form of laziness (like Python+Iterators).

 Can you post some?

 Cristiano
 ___
 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] Combine to List to a new List

2009-06-09 Thread Andrew Wagner
Try c = zip a b

On Tue, Jun 9, 2009 at 9:05 AM, ptrash ptr...@web.de wrote:


 Hi,

 I have the following two lists:

 a = [1,2,3]
 b = [A,B,C]

 I want a combination of the to lists:

 c = [(1,A), (2, B), (3, C)]

 How can I do this?

 I have tried

 c = [(x,y) | x - a, y - b]

 But this  just returns me a list with every possible combination of the 2
 lists.

 Thanks...


 --
 View this message in context:
 http://www.nabble.com/Combine-to-List-to-a-new-List-tp23942440p23942440.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

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


Re: [Haskell-cafe] Problem w/YAHT code example

2009-05-28 Thread Andrew Wagner
I'm not sure what you're using at the end of the identifier search', but
it needs to be the single quote that's on the same key as the double quotes.
I suspect that's where it's blowing up.

On Thu, May 28, 2009 at 9:56 PM, michael rice nowg...@yahoo.com wrote:

 This code, from YAHT (Section 8.4.2, PDF pg. 119 of 192) seems to have a
 problem. Code below.

 Michael

 =

 [mich...@localhost ~]$ ghci
 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 :l graph
 [1 of 1] Compiling Main ( graph.hs, interpreted )

 graph.hs:6:24: lexical error at character '\8217'
 Failed, modules loaded: none.

 ==

 Prelude data Graph v e = Graph [(Int,v)] [(Int,Int,e)]

 search :: Graph v e - Int - Int - Maybe [Int]
 search g@(Graph vl el) src dst
 | src == dst = Just [src]
 | otherwise = search’ el
 where search’ [] = Nothing
   search’ ((u,v,_):es)
   | src == u =
 case search g v dst of
   Just p - Just (u:p)
   Nothing - search’ es
   | otherwise = search’ es






 ___
 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] Re: [Haskell-cafe] ANN: Haskell Hackathon in Philadelphia

2009-05-24 Thread Andrew Wagner
Is there a list of projects that will be worked on during this, or how will
that work?

On Thu, May 21, 2009 at 5:39 PM, Brent Yorgey byor...@seas.upenn.eduwrote:

 Hi all!

 We are in the early stages of planning a Haskell hackathon/get
 together, Hac φ, to be held this summer at the University of
 Pennsylvania, in Philadelphia.  Right now we're looking at two
 possible dates:

  June 19-21or   July 24-26

 If you might be interested in attending, please add your name on the
 wiki page:

  http://www.haskell.org/haskellwiki/Hac_%CF%86

 You can also note whether either of those dates absolutely doesn't
 work for you.  (If you don't have an account on the wiki, you can
 email Ashley Yakeley for an account [1], or feel free to just respond
 to this email.)  Expect more details (such as a nailed-down date)
 soon, once we have gauged the level of interest.

 Hope to see you in Philadelphia!

 Brent (byorgey)
 Daniel Wagner (dmwit)

 [1] http://haskell.org/haskellwiki/HaskellWiki:New_accounts
 ___
 Haskell-Cafe mailing list
 haskell-c...@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

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


Re: [Haskell-cafe] ANN: Haskell Hackathon in Philadelphia

2009-05-24 Thread Andrew Wagner
Is there a list of projects that will be worked on during this, or how will
that work?

On Thu, May 21, 2009 at 5:39 PM, Brent Yorgey byor...@seas.upenn.eduwrote:

 Hi all!

 We are in the early stages of planning a Haskell hackathon/get
 together, Hac φ, to be held this summer at the University of
 Pennsylvania, in Philadelphia.  Right now we're looking at two
 possible dates:

  June 19-21or   July 24-26

 If you might be interested in attending, please add your name on the
 wiki page:

  http://www.haskell.org/haskellwiki/Hac_%CF%86

 You can also note whether either of those dates absolutely doesn't
 work for you.  (If you don't have an account on the wiki, you can
 email Ashley Yakeley for an account [1], or feel free to just respond
 to this email.)  Expect more details (such as a nailed-down date)
 soon, once we have gauged the level of interest.

 Hope to see you in Philadelphia!

 Brent (byorgey)
 Daniel Wagner (dmwit)

 [1] http://haskell.org/haskellwiki/HaskellWiki:New_accounts
 ___
 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] Haskell in 3 Slides

2009-05-18 Thread Andrew Wagner
Don't forget to include higher-order functions in one of those important
points.

On Mon, May 18, 2009 at 12:36 PM, John Van Enk vane...@gmail.com wrote:

 Thanks Joe,

 Your assumption is correct--the whole presentation will be longer. I wanted
 to use 3 or 4 slides to introduce the language and the balance for the
 interesting stuff. :P

 /jve

 PS to Joe: I will not forget to reply to all. I will not forget to reply to
 all. I will not forget to reply to all. There, hopefully I won't forget any
 more. :)

 On Mon, May 18, 2009 at 12:29 PM, Joe Fredette jfred...@gmail.com wrote:

 While an incredibly small font is a clever option, a more serious
 suggestion may be as follows.

 3-4 slides imply 3-4 topics, so the question is what are the 3-4 biggest
 topics in haskell? I would think they would be:

 * Purity/Referential Transparency
 * Lazy Evaluation
 * Strong Typing + Type Classes
 * Monads

 Assuming you have, say, 10-15 minutes for the talk, and the people there
 are versed with imperative programming and maybe have some experience in
 functional programming, you can probably jump over each of those slides in
 about a minute, just enough to touch the subject.

 I also assume that you don't need to fit the whole presentation in 3-4
 slides, if you do, then  yah.


 /Joe


 David Leimbach wrote:

 Use an incredibly small font.

 On Mon, May 18, 2009 at 8:16 AM, John Van Enk vane...@gmail.commailto:
 vane...@gmail.com wrote:

Hi all,
I'm giving a presentation to an IEEE group on Embedded DSL's and
Haskell at the end of June. I need a 3 to 4 slide introduction to
Haskell. What suggestions does the community have? Is such a short
intro possible?
It just needs to introduce the basics so I can show some code
without alienating the audience. I'm hoping some one else has
attempted this before, but if not, some boiler plate slides could
be useful for every one!

--/jve

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org mailto: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





 --
 /jve

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


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


Re: [Haskell-cafe] Pretty printing a tree

2009-05-14 Thread Andrew Wagner
Perhaps drawTree on
http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Tree.html
2009/5/14 José Romildo Malaquias j.romi...@gmail.com

 Hello.

 I would like to pretty print a tree in a way that its structure is
 easily perceived.

 For instance, consider the declarations:

   data Node a = Node a [Node a]

   type Tree a = [ Node a ]

   t = [ Node a [ Node b []
  , Node c [ Node c1 []
 , Node c2 [] ]
  , Node d [ Node d1 [ Node d1a [] ]
 , Node d2 [] ] ] ]

 Then the resulting of pretty printing the given tree would be something
 like the following:

   a
   |
 +-+
 |||
 bcd
 ||
   +---++---+
   |   ||   |
   c1  c2   d1  d2
|
   d1a

 There is the module Text.PrettyPrint.HughesPJ, but it lacks examples on
 how to use the pretty print combinators, and it is not well docomented.

 I would like to see solutions for this problem, or clues on how to solve
 it.

 Regards,

 José Romildo
 ___
 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] Structural sharing in haskell data structures?

2009-05-13 Thread Andrew Wagner

 So far as I know, all immutable languages do it. Like Don, I think the
 reason it's emphasized so much in Clojure is because of trying to convert
 the Java crowd and introducing them to immutability. With mutable languages
 you have to clone _everything_ for fear of later changes affecting earlier
 copies. Because of this, folks used to mutable languages often erroneously
 suppose that immutable languages do the same thing. There's a lot of FUD in
 the mainstream about declarative/immutable/functional languages and their
 performance behavior.

 The idea is simple and you can do it in mutable languages perfectly well
 (clone the changed part of the spine, point to old substructure) so long as
 you're careful not to do mutation, e.g. by marking everything final. You
 don't see it as much in mutable languages because people get squeamish about
 the first step: clone the changed spine; they'd much rather mutate it. In
 heavily GCed languages like Haskell allocation and collection is cheap, so
 we don't mind too much; but in Java and the like, both allocation and
 collection are expensive so the idea of cheap throwaway objects is foreign.


Are you guys saying that the Clojure target audience is current Java
programmers, whereas Haskell's is people who already do functional,
immutable programming? Because how long the technique has been used, or how
widespread it's used, is irrelevant when trying to convince someone who
doesn't have experience with immutable data structures that it's not
completely insane.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Structural sharing in haskell data structures?

2009-05-12 Thread Andrew Wagner
So I've been reading a lot about a (relatively) new language called Clojure.
One of its goals is to make concurrency easier via a built-in home-grown
STM. Anyway, one of the ways it tries to do this is to have completely
immutable data structures. Every time I read a tutorial about this in
Clojure, it says ...yes, it sounds awful to think that your whole data
structure gets copied every time you want to make a change to it, but it's
sane because of a technique called structural sharing. Yet every time I
hear immutability talked about in Haskell, what I hear is ...yes, it sounds
awful to think that your whole data structure gets copied every time you
want to make a change to it, but it's sane because of laziness...unless you
need the whole data structure So I'm just curious, does GHC use
structural sharing or something similar? Do other implementations? Does it
matter?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] List of exports of a module - are there alternatives?

2009-05-12 Thread Andrew Wagner
On Tue, May 12, 2009 at 10:05 AM, Maurício briqueabra...@yahoo.com wrote:
snip

 (I think something like that could be nice when we have modules
 with 200 declarations and just a few are (not) going to be
 exported.)

 Thanks,
 Maurício


Uh, show me such a module, and I'll show you a module that's quite bloated
and desperately needs to be refactored.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Structural sharing in haskell data structures?

2009-05-12 Thread Andrew Wagner

 Purity allows our data structures to have a lot of sharing.
 This is separate to laziness.


Ah, so haskell does do it. Interesting that it so rarely comes up, whereas
it's frequently mentioned in clojure.



 Laziness lets us build up interesting structures that have unusual
 sharing.

 Actually, what kind of persistant structures does Clojure have at this
 stage? I was under the impression they were reusing Java data
 structures. E.g. some of the nicer ones on hackage are zippers, patricia
 tries, finger trees, which I can't imaging have been ported.


It has some built-in persistent data structures: lists, vectors (arrays),
maps, and sets. It also has strong interoperability with Java, so that any
existing Java library can easily be used in Clojure code. In some ways, that
makes it a VERY mature language already.


 -- Don

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


[Haskell-cafe] Poking fun at haskell and other programming languages

2009-05-08 Thread Andrew Wagner
http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Andrew Wagner
Err, I'm not seeing the danger of this
(+) :: forall a. (Num a) = a - a - a

Doesn't this require the two parameters to be the same instance of Num?

On Fri, May 8, 2009 at 10:51 AM, Sittampalam, Ganesh 
ganesh.sittampa...@credit-suisse.com wrote:

 Stephan Friedrichs wrote:

  When looking for an xor function, I found one in Data.Bits but
  couldn't use it for Bool, because Bool is no instance of Bits and of
  Num (which would be necessary, because it's class (Num b) = Bits
  b). My question is: Why not?
 
  [...]
  quite trivial... Why is this not part of base? Or am I missing
  something?

 One reason would be that we don't want 1 + True to typecheck, even if it
 does have a sensible interpretation.

 Ganesh


 ===
  Please access the attached hyperlink for an important electronic
 communications disclaimer:
  http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html

  
 ===

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

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


Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Andrew Wagner
Hmm, I never knew that. Is that a GHC thing? Is it strictly necessary? Seems
like it could be done in the Num instance for Integers, Ints, etc.

On Fri, May 8, 2009 at 11:51 AM, Neil Mitchell ndmitch...@gmail.com wrote:

  Err, I'm not seeing the danger of this
  (+) :: forall a. (Num a) = a - a - a
  Doesn't this require the two parameters to be the same instance of Num?

 I didn't at first, then I remembered:

 1 + True
 =
 fromInteger 1 + True

 And if we have Num for Bool, it type checks.

 Thanks

 Neil

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


Re: [Haskell-cafe] How difficult would creating a collaborative multi-user online virtual world application be in Haskell?

2009-05-07 Thread Andrew Wagner
This reminds me of a server app I saw recently in a language called  
Clojure. Clojure is a relatively new lisp variant targeting the JVM,  
and has a home-grown STM layer built into the language. Anyway, the  
app I saw was a (admittedly didactic-focused) multi-threaded MUD  
server (google clojure mire), which could easy serve as the  
foundation for a project like this. Thus, I would say that STM is up  
for the challenge. The question in my mind would be whether or not  
Haskell's graphics/video libraries are mature enough.


On May 7, 2009, at 6:28 AM, Benjamin L.Russell  
dekudekup...@yahoo.com wrote:



One question that has been coming up at the back of my mind for the
past several weeks has been how difficult would it be to create a
collaborative multi-user online virtual world application in Haskell.

More specifically, last August, I came across a very interesting
application called Croquet (see
http://www.opencroquet.org/index.php/Main_Page), which happens to be
based on Squeak (see http://www.squeak.org/), a dialect of Smalltalk.
Croquet, in turn, provides the basis for Cobalt (see
http://www.duke.edu/~julian/Cobalt/Home.html), a virtual workspace
browser and construction toolkit for accessing, creating, and
publishing hyperlinked multi-user virtual environments (according to
the home page for that project).

What struck me as especially interesting was how Croquet allows
multiple users to collaborate together in a multi-user online virtual
world in software development and other collaborative projects.  As
one application, the video clip on the upper-right-hand corner of the
above-mentioned Croquet home page illustrates how a user can, by
writing code from inside the application, create on-the-fly additional
virtual environments, which can then be entered by either the
programmer or other programmers.  Other applications (shown in other
video clips on the Screenshots/Videos page (see
http://www.opencroquet.org/index.php/Screenshots/Videos) show
alternative applications that include text-based annotations, a 3D
spreadsheet, and writing a conventional blog from within a virtual
world.

Unfortunately, Smalltalk is an object-oriented language.  If possible,
I would like to see something similar in a functional programming
language such as Haskell.

Does anybody know whether duplicating this project in Haskell would be
feasible?

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


Re: [Haskell-cafe] Interesting Thread on OO Usefulness (scala mailing list)

2009-05-04 Thread Andrew Wagner
This sounds like a really interesting question. To save some people weeding
through the thread and Jon Harrop's usual trolling garbage, here's a
description of the problem:
[quote]
Here's [a]language to to interpret (where postfix * means tupling):

Variables: x
Integer literals: i
Terms:

t = Lambda x*. t
  |  Apply t t*
  |  Var(x)
  |  Num(i)

We assume usual operational semantics of lambda calculus (i.e. static
scoping).

The task is to write two interpreters, one with variables x being
DeBruijn indices and one with them being names.
You should go for maximal sharing, i.e. factor out commonalities into
a common class/typeclass/functor/whatever, so that there remains no
duplication of code in the two solutions.
[/quote]


On Mon, May 4, 2009 at 6:05 AM, Paolo Losi paolo.l...@gmail.com wrote:

 Hi all,

 I'm following an interesting thread on the scala mailing list:

 http://www.nabble.com/-scala--usefulness-of-OOP-td23268250.html

 Martin Odersky advocates the OO features of the scala language
 proposing an interesting problem where the OO approach seams
 valuable.

 I would be very much interested in seeing an Haskell solution
 to that problem. Any haskell guru want to take a stub at it
 or give an opinion from a pure FP point of view?

 Thanks
 Paolo

 ___
 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] [ANN] Hack: a sexy Haskell Webserver Interface ^^

2009-04-20 Thread Andrew Wagner
Err, is there some reason you don't have simpler interfaces like:plaintext
:: String - Application
plaintext text = \env - return $ Response
   { status  = 200
   , headers = [ (Content-Type, text/plain) ]
   , body= text
}

On Mon, Apr 20, 2009 at 12:30 PM, Joe Fredette jfred...@gmail.com wrote:

 We need to start referring to more haskell packages as sexy

 /Joe

 Jinjing Wang wrote:

 Simplest app should look like this

module Main where

import Hack
import Hack.Handler.Kibro

hello :: Application
hello = \env - return $ Response
{ status  = 200
, headers = [ (Content-Type, text/plain) ]
, body= Hello World
}

main = run hello

 Hack is a brainless port of the brilliant Ruby Rack framework. Rack is
 very modular and that's
 very important.

 Rack utilities and middlewares should be able to be ported with
 minimal effort, I hope.

 link / source: http://github.com/nfjinjing/hack/tree/master




 ___
 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] Looking for the fastest Haskell primes algorithm

2009-04-14 Thread Andrew Wagner
Some other ideas for things to put in this package possibly:
is_prime :: Int - Bool
nth_prime :: Int - Int -- or Int - Integer
prime_factors :: Int - [Int]

I'm assuming there are faster ways of doing the first 2 than by just simply
looking through all of primes. Someone should also look through Euler - I'm
sure that will generate other ideas of things that could be useful in
playing with primes.

On Tue, Apr 14, 2009 at 8:40 AM, Niemeijer, R.A. r.a.niemei...@tue.nlwrote:

  Today I happened to need a large list of prime numbers. Obviously this is
 a well-known problem, so I figured there would be something on Hackage that
 I could use. Surprisingly, there isn’t, or if there is it’s not easy to
 find. Searching for prime or primes on Hackage reveals nothing. Searching
 for primes on Hayoo gives Codec.Encryption.RSA.NumberTheory, but that uses
 the inefficient one-liner implementation. The HaskellWiki article on primes
 (http://www.haskell.org/haskellwiki/Prime_numbers) has a number of
 implementations, but the faster they get, the longer and uglier they become.



 Since it’s such a common problem I’d say it would be a good idea to add a
 package to Hackage that exports

 primes :: [Integer]

 and hides the ugly implementation details. Data.Numbers.Primes seems a
 logical choice for the namespace, but I’m open to suggestions.



 The trick then is to find the most efficient implementation of primes. The
 Haskell wiki article mentions ONeillPrimes.hs as one of the fastest ones,
 but maybe there’s a faster version. So my question is: does anybody know
 what the fastest Haskell algorithm for generating primes is?

 ___
 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] Converting IO [XmlTree] to [XmlTree]

2009-04-14 Thread Andrew Wagner
Here's another way of looking at what others have already said. The only way
you can do that is within the scope of another IO action. For example:
outputXmlTrees :: IO ()
outputXmlTrees = do
  trees - inputXmlTrees;
  let newTrees = transform trees;
  print . show $ newTrees

Notice a few things:

   -   First, the line trees - inputXmlTrees effectively takes an IO
   [XmlTree] and turns it into a [XmlTrees]. That is, it runs the IO action
   inputXmlTrees, and gives you the resulting list of XmlTrees to work with.
   - You can then pass these off to a pure function which will monkey around
   with them in a pure (non-IO) context
   - You must do this in an IO action, however, and any monadic action gets
   its type from the last line. Thus, the last line must be of type IO
   something. In this case, it is simply the action that would print out the
   trees.
   - Thus, this gives you a way to glue together different IO actions and
   pure actions and combine them into larger IO actions

Hope this clarifies

On Tue, Apr 14, 2009 at 10:54 AM, rodrigo.bonifacio 
rodrigo.bonifa...@uol.com.br wrote:

 Dear Sirs,

 I guess this is a very simple question. How can I convert IO [XmlTree] to
 just a list of XmlTree?

 Regards,

 Rodrigo.



 ___
 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] community.haskell.org unreachable?

2009-04-06 Thread Andrew Wagner
Works for me. The admin address referenced there is support [AT]
community.haskell.org

On Mon, Apr 6, 2009 at 1:32 PM, Claus Reinke claus.rei...@talk21.comwrote:

 I seem to be having problems reaching anything on that server.
 Does anyone know what is going on, or who to contact? It would
 help if the haskellwiki page

 http://www.haskell.org/haskellwiki/Haskell.org_domain

 would mention the admin address directly, instead of referring to

 http://community.haskell.org/admin/
 which is also unreachable.

 Claus

 ___
 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] happstack example code wanted

2009-04-04 Thread Andrew Wagner
Copied there.

On Sat, Apr 4, 2009 at 1:30 PM, Thomas Hartman tphya...@gmail.com wrote:

 Johannes,

  You'll have a better response if you post to the happs list.

  Have you had a look at tutorial.happstack.com?

  Thomas.

 2009/4/4 Johannes Waldmann waldm...@imn.htwk-leipzig.de:
  Hi, I'm thinking of using happstack for a simple
  online registration system. [ Customer gives
  Name and Address and registers for certain workshops.
  Then the app server should just produce a bill.
  (Payment is handled through a different channel.)
  The store owner needs to get some overview of
  registrations. ] According to happs(tack) marketing
  department, this should be an easy exercise?
  Any code that I could use as a starting point?
  ( Or, if you do the coding, I can link to you from
  the workshop site. But I don't have a serious budget :-)
  Thanks - J.W.
 
 
  ___
  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] Combining sequences

2009-04-04 Thread Andrew Wagner
Here's a pretty straightforward approach:

combine [] ys = ys
combine xs [] = xs
combine (x:xs) (y:ys) | x = y = x : combine xs (y:ys)
  | otherwise = y : combine (x:xs) ys

On Sat, Apr 4, 2009 at 8:40 PM, michael rice nowg...@yahoo.com wrote:

 Is there a simple way to combine two sequences that are in ascending order
 into a single sequence that's also in ascending order? An example would be
 the squares [1,4,9,16,25..] combined with the cubes [1,8,27,64,125..] to
 form [1,1,4,8,9,16,25,27..].

 Michael



 ___
 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] Monad transformer, liftIO

2009-04-03 Thread Andrew Wagner
You haven't really said what happens when you try this, but I would bet that
things would be clarified greatly if you put type signatures on your two
definitions.

On Fri, Apr 3, 2009 at 12:49 PM, Michael Roth mr...@nessie.de wrote:

 Hello list,

 maybe I'm just stupid, I'm trying to do something like this:


import Control.Monad
import Control.Monad.Trans
import Control.Monad.List

foobar = do
a - [1,2,3]
b - [4,5,6]
liftIO $ putStrLn $ (show a) ++   ++ (show b)
return (a+b)

main = do
sums - foobar
print sums


 But this apparently doesn't work... I'm total clueless how
 to achieve the correct solution. Maybe my mental image
 on the monad transformer thing is totally wrong?


 Michael
 ___
 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] The votes are in!

2009-03-24 Thread Andrew Wagner
Ooh, let me pop some popcorn!

2009/3/24 John Van Enk vane...@gmail.com

 Is this the part where all the pundits come out and talk about how Jeff
 isn't a citizen, eats babies, and wants to turn Haskell into an imperative
 language?

 /jve


 2009/3/24 Eelco Lempsink ee...@lempsink.nl

 The results of the Haskell logo competition are in!

 You can view them at 
 http://www.cs.cornell.edu/w8/~andru/cgi-perl/civs/http://www.cs.cornell.edu/w8/%7Eandru/cgi-perl/civs/
 results.pl?num_winners=1id=E_d21b0256a4fd5ed7algorithm=beatpath

 Congratulations Jeff Wheeler!

 I'll set up a page with the results visibile.

 --
 Regards,

 Eelco Lempsink


 ___
 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] The votes are in!

2009-03-24 Thread Andrew Wagner
He ONCE used unsafeInterleaveIO, but he never evaluated it, and never tried
it again!

2009/3/24 Brandon S. Allbery KF8NH allb...@ece.cmu.edu

 On 2009 Mar 24, at 8:29, John Van Enk wrote:

 Is this the part where all the pundits come out and talk about how Jeff
 isn't a citizen, eats babies, and wants to turn Haskell into an imperative
 language?


 He uses unsafeInterleaveIO!

 --
 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



 ___
 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] [ANN] random-stream package

2009-03-19 Thread Andrew Wagner
Maybe the feature has been added, but not released, because somebody is
strict about their code...




 It should be possible to do:
 cabal install http://haskell.mperillo.ath.cx/random-stream-0.0.1.tar.gz

 It's unfortunate that this is not supported.


 Thanks  Manlio
 ___
 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] Abuse of the monad [was: monadic logo]

2009-03-12 Thread Andrew Wagner
Can you expand on this a bit? I'm curious why you think this.

On Thu, Mar 12, 2009 at 10:13 AM, Thomas Davie tom.da...@gmail.com wrote:


 On 12 Mar 2009, at 15:04, Gregg Reynolds wrote:

  At risk of becoming the most hated man in all Haskelldom, I'd like to
 suggest that the Haskell logo not use lambda symbols.  Or at least not as
 the central element.  Sorry, I know I'm late to the party, but the thing is
 there is nothing distinctive about lambda; it's common to all FPLs.
  Besides, Lisp/Scheme already have that franchise.

 What is distinctive about Haskell it's use of the monad.  The Pythagorean
 monad symbol is wonderfully simple:

 No, what's distinctive about Haskell is usually the abuse of the monad.

 Encouraging people to think Haskell is all about monadic programming even
 more is a recipe for disaster.

 Just my 2¢

 Bob___

 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] Abuse of the monad [was: monadic logo]

2009-03-12 Thread Andrew Wagner
Hmm, perhaps what we need is another monad tutorial that.err...never
mind. Actually, I'd like to see more written about Applicatives. I think
they just finally clicked with me when reading the Typeclassopedia, and
seeing the intended way to use them. Before it was always like ok...so, if
I've got a function already in my functor, I could use this, but...why would
I have that?

On Thu, Mar 12, 2009 at 10:28 AM, Thomas Davie tom.da...@gmail.com wrote:


 On 12 Mar 2009, at 15:16, Andrew Wagner wrote:

  Can you expand on this a bit? I'm curious why you think this.


 For two reasons:

 Firstly, I often find that people use the Monadic interface when one of the
 less powerful ones is both powerful enough and more convenient, parsec is a
 wonderful example of this.  When the applicative instance is used instead of
 the monadic one, programs rapidly become more readable, because they stop
 describing the order in which things should be parsed, and start describing
 the grammar of the language being parsed instead.

 Secondly, It seems relatively common now for beginners to be told about the
 IO monad, and start writing imperative code in it, and thinking that this is
 what Haskell programming is.  I have no problem with people writing
 imperative code in Haskell, it's an excellent imperative language.  However,
 beginners seeing this, and picking it up is usually counter productive –
 they never learn how to write things in a functional way, and miss out on
 most of the benefits of doing so.

 Hope that clarifies what I meant :)

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


Re: [Haskell-cafe] Abuse of the monad [was: monadic logo]

2009-03-12 Thread Andrew Wagner
Conal,Do you think imperative Haskell can be a sort of gateway drug to
real haskell?

On Thu, Mar 12, 2009 at 11:25 AM, Conal Elliott co...@conal.net wrote:

 Thank you Bob!  I'll throw in another 2 cents:

 Yes, *one* aspect of Haskell is that it's a power tool for imperative
 programming -- a clever way to keep plugging away at the old sequential von
 Neumann paradigm.  C.

 I'd rather we strongly encourage Haskell-newbies toward shifting out of the
 imperative paradigm to thinking and programming *functionally*.  It's a big
 shift, to make, and imperative-Haskell is a relatively easy substitute.

- Conal

 On Thu, Mar 12, 2009 at 7:28 AM, Thomas Davie tom.da...@gmail.com wrote:


 On 12 Mar 2009, at 15:16, Andrew Wagner wrote:

  Can you expand on this a bit? I'm curious why you think this.


 For two reasons:

 Firstly, I often find that people use the Monadic interface when one of
 the less powerful ones is both powerful enough and more convenient, parsec
 is a wonderful example of this.  When the applicative instance is used
 instead of the monadic one, programs rapidly become more readable, because
 they stop describing the order in which things should be parsed, and start
 describing the grammar of the language being parsed instead.

 Secondly, It seems relatively common now for beginners to be told about
 the IO monad, and start writing imperative code in it, and thinking that
 this is what Haskell programming is.  I have no problem with people writing
 imperative code in Haskell, it's an excellent imperative language.  However,
 beginners seeing this, and picking it up is usually counter productive –
 they never learn how to write things in a functional way, and miss out on
 most of the benefits of doing so.

 Hope that clarifies what I meant :)


 Bob___
 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] Abuse of the monad [was: monadic logo]

2009-03-12 Thread Andrew Wagner
I was thinking the same thing. If I remember correctly, RWH does a parser in
an applicative style, but I'll have to look when I get home to be sure. If
so, then maybe we could try doing the same thing in a monadic style, for
comparison and contrast purposes.

On Thu, Mar 12, 2009 at 11:29 AM, Jeff Heard jefferson.r.he...@gmail.comwrote:

 Come to think of it, I've never seen an applicative tutorial of
 Parsec, only a monadic one.  Does such a beast exist, and if so, maybe
 we could merge the two together, work the same example in both, and
 thus help the programmer make the shift from monadic to applicative,
 from order of parsing to describing the grammar.

 -- Jeff

 2009/3/12 Conal Elliott co...@conal.net:
  Thank you Bob!  I'll throw in another 2 cents:
 
  Yes, *one* aspect of Haskell is that it's a power tool for imperative
  programming -- a clever way to keep plugging away at the old sequential
 von
  Neumann paradigm.  C.
 
  I'd rather we strongly encourage Haskell-newbies toward shifting out of
 the
  imperative paradigm to thinking and programming *functionally*.  It's a
 big
  shift, to make, and imperative-Haskell is a relatively easy substitute.
 
 - Conal
 
  On Thu, Mar 12, 2009 at 7:28 AM, Thomas Davie tom.da...@gmail.com
 wrote:
 
  On 12 Mar 2009, at 15:16, Andrew Wagner wrote:
 
  Can you expand on this a bit? I'm curious why you think this.
 
  For two reasons:
 
  Firstly, I often find that people use the Monadic interface when one of
  the less powerful ones is both powerful enough and more convenient,
 parsec
  is a wonderful example of this.  When the applicative instance is used
  instead of the monadic one, programs rapidly become more readable,
 because
  they stop describing the order in which things should be parsed, and
 start
  describing the grammar of the language being parsed instead.
 
  Secondly, It seems relatively common now for beginners to be told about
  the IO monad, and start writing imperative code in it, and thinking that
  this is what Haskell programming is.  I have no problem with people
 writing
  imperative code in Haskell, it's an excellent imperative language.
  However,
  beginners seeing this, and picking it up is usually counter productive –
  they never learn how to write things in a functional way, and miss out
 on
  most of the benefits of doing so.
 
  Hope that clarifies what I meant :)
 
  Bob___
  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

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


Re: [Haskell-cafe] Partial pattern matching

2009-03-09 Thread Andrew Wagner
The question is, is there some very important reason you can't do this?
firstCoord (P x _) = x

2009/3/9 Peter Verswyvelen bugf...@gmail.com

 In Haskell, a data constructor can be used partially applied:
 data Pair a b = P a b

 f = P 1

 however, I cannot do partial pattern matching, e.g

 firstCoord (P x) = x

 does not work.

 I guess a very important reason must exist why this is the case?






 ___
 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] Purely Functional Data Structures

2009-03-08 Thread Andrew Wagner
So...is there some reason this is in the hApps package?

On Sat, Mar 7, 2009 at 9:04 PM, Jeremy Shaw jer...@n-heptane.com wrote:

 At Sun, 08 Mar 2009 00:13:14 +0100,
 G?uenther Schmidt wrote:
  In SQL I would have the data indexed by several
  different columns, if I use maps I'd only have one key, so if I need to
  lookup data in the map by a value that is not the key the lookups will
  become quite expensive.

 happstack-ixset offers a data-type similar to Map except that you can
 have multiple keys. You can even have keys that are calculated from
 the data but don't actually appear in the data itself. For, example,
 if your ixset just contains Strings, one of the keys could be the
 length of the String.

 happstack-ixset (and its dependencies) also offers compact
 serialization/deserialization of the ixset to disk, data migration
 options, and a smattering of other features that may or may not be
 useful to you.

 While happstack-ixset is built to work with happstack, it is does not
 depend on the happstack http server or persistent store layer, so it
 should be useful even if you are not being an application server.

 - jeremy
 ___
 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] Finding the Convex Hull (Problem 12 of Real World Haskell)

2009-03-05 Thread Andrew Wagner
Whenever I'm looking for a bug in Haskell code, I find it helpful to start
by seeing if I can simplify the code any first. In this case, there are a
couple of things I notice:

   - validPointsOf is just a filter. It would be easier to write valid ::
   MyDirection - Bool and then validPointsOf = filter (valid . snd)
   - Similarly, there's no need to write your own minimum-finder and call it
   lowestY. Instead, write (or derive!) an Ord instance, and then use the
   standard prelude function minimum
   - a small simplification of sortByCoTan: sortByCoTan pivot = sortBy
   (comparing (coTan pivot))

Hope this helps!

2009/3/5 Rob Crowther weila...@gmail.com

 I wrote a solution to this problem, but it appears to return incorrect
 results. There's a pastebin of the code at
 http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2121 and a picture of the
 inputs, outputs, and expected results graphed at
 http://img510.imageshack.us/img510/9971/resultsg.jpg

 I'm wondering if this is a flaw in my code, my understanding of the
 problem, or both. Any ideas on how to track this one down would be very much
 appreciated.

 Thank you!

 --
 ヽ(^o^)ノ  -rob

 ___
 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] DSLs with {in,}equalities

2009-03-03 Thread Andrew Wagner
Not to hijack the thread, but I thought I was the only one that used unix
notation for statements like {in,}equalities. I like it!

On Mon, Mar 2, 2009 at 11:13 PM, Andrew Hunter ahun...@cs.hmc.edu wrote:

 Several times now I've had to define an EDSL for working with
 (vaguely) numeric expressions.  For stuff like 2*X+Y, this is easy,
 looking pretty much like:

  data Expr = Const Integer | Plus Expr Expr | Times Expr Expr
 
  instance Num Expr where
  fromInterger = Const
  (+) = Plus
  (*) = Times

 c.  This lets me get a perfectly nice AST, which is what I want.
 When I want to be able to express and work with inequalities and
 equalities, this breaks.  Suppose I want to write 2*X + Y  3.  I
 either have to:

 a) Hide Prelude.() and define a simple  that builds the AST term I want.
 b) Come up with a new symbol for it that doesn't look totally awful.

 Neither of these work decently well.  Hiding Eq and Ord operators,
 which is what I effectively have to do for a), is pretty much a
 nonstarter--we'll have to use them too much for that to be practical.

 On the other hand, b) works...but is about as ugly as it gets.  We
 have lots and lots of symbols that are already taken for important
 purposes that are syntactically near ,=,==, and the like:  and
  and = for monads,  for arrows, etc.  There...are not good
 choices that I know of for the symbols that don't defeat the purpose
 of making a nice clean EDSL for expressions; I might as well use 3*X +
 Y `lessthan` 3, which is just not cool.

 Does anyone know of a good solution, here?  Are there good
 substitutions for all the six operators that are important
 (,,=,=,==,/=), that are close enough to be pretty-looking but not
 used for other important modules?

 Better yet, though a little harder, is there a nice type trick I'm not
 thinking of?  This works for Num methods but not for Ord methods
 because:

 (+) :: (Num a) = a - a - a
 () :: (Ord a) = a - a - Bool

 i.e. the return type of comparisons is totally fixed.  I don't suppose
 there's a good way to...well, I don't know what the *right* answer is,
 but maybe define a new typeclass with a more flexible type for  that
 lets both standard types return Bool and my expressions return Expr?
 Any good solution would be appreciated.

 Thanks,
 AHH
 ___
 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] DSLs with {in,}equalities

2009-03-03 Thread Andrew Wagner
Err, I was actually talking about the thread subject, where he actually has
the word {in,}equalities, short for inequalities and equalities (more or
less). AFAIK, that's unix notation.

On Tue, Mar 3, 2009 at 12:36 PM, Brandon S. Allbery KF8NH 
allb...@ece.cmu.edu wrote:

 On 2009 Mar 3, at 12:25, Andrew Wagner wrote:

 Not to hijack the thread, but I thought I was the only one that used unix
 notation for statements like {in,}equalities. I like it!


 It's actually closer to Windows notation with the bracket on both sides
 (and I actually considered making it %% but to me that looks more
 cluttered, plus the S-curve in $ can be a mnemonic for symbolic for those
 who don't live their lives on Unix).

 --
 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



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


Re: [Haskell-cafe] Difficulties in accessing inner elements of data types

2009-03-03 Thread Andrew Wagner
Seems like Conal's semantic editor combinators could be of interest too, if
I'm understanding correctly:
http://conal.net/blog/posts/semantic-editor-combinators/

On Tue, Mar 3, 2009 at 8:00 PM, Tim Docker t...@dockerz.net wrote:

  While writing an OrgFile is fairly easy, reading (and
  accessing inner parts) of an org file is very tedious,
  and modifying them is horrendous.

 Have you looked at

 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/data-accessor

 It's something I've used successfully when wanting to
 manipulate the internals of complex types.

 Tim


 ___
 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] Stacking State on State.....

2009-03-01 Thread Andrew Wagner
I know very little about profiling, but your comment about spending a lot of
time garbage collecting rang a bell with me - the example on RWH talks about
that exact issue. Thus, I would recommend walking through the profiling
techniques described on
http://book.realworldhaskell.org/read/profiling-and-optimization.html .

On Sun, Mar 1, 2009 at 3:03 PM, Phil pbeadl...@mail2web.com wrote:

 Hi,

 Thanks for the replies - I haven't had a chance to try out everything
 suggested yet - but your explanations of transformers nailed it for me.

 However, in terms of performance when stacking, I've come across something
 I'm struggling to explain - I was wondering if anyone could offer up and
 explanation.
 I've rewritten my code twice - one with 3 stacked monads, and one with 2
 stacked monads and a load of maps.  Heuristically I would have thought the
 3
 stacked monads would have performed as well, or even better than the 2
 stacked solution, but the 2 stacked solution is MUCH faster and MUCH less
 memory is used.  They are both using 90% of the same code and both chain
 together the same number of computations using replicateM.  From profiling
 I
 can see that the pure function 'reflect' takes up most of the umph in both
 cases - which I'd expect.  But in the triple stacked version the garbage
 collector is using up 90% of the time.

 I've tried using BangPatterns to reduce memory usage in the Triple Stack
 version - doing this I can half the time it takes, but it is still running
 at over twice the time of the two stack version.  The BangPatterns were
 also
 put in Common Code in the reflect function - so I'd expect both solutions
 to
 need them?

 Even though both pieces of code are a bit untidy, the triple stacked monad
 'feels' nicer to me - everything is encapsulated away and one evaluation in
 main yields the result.  From purely a design perspective I prefer it - but
 obviously not if it runs like a dog!

 Any ideas why the triple stack runs so slow?

 Thanks again!

 Phil

 * Triple Stack Specific Impl:

 type MonteCarloStateT = StateT Double

 mc :: MonteCarloStateT BoxMullerQuasiState ()
 mc = StateT $ \s - do nextNormal - generateNormal
   let stochastic = 0.2*1*nextNormal
   let drift = 0.05 - (0.5*(0.2*0.2))*1
   let newStockSum = payOff 100 ( 100 * exp ( drift +
 stochastic ) ) + s
   return ((),newStockSum)

 iterations = 100
 main :: IO()
 main = do let sumOfPayOffs = evalState ( evalStateT ( execStateT (do
 replicateM_ iterations mc) $ 0 ) $ (Nothing,nextHalton) ) $ (1,[3,5])
  let averagePO = sumOfPayOffs / fromIntegral iterations
  let discountPO = averagePO * exp (-0.05)
  print discountPO


 * Double Stack and Map Specific Impl:


 iterations = 100
 main :: IO()
 main = do let normals = evalState ( evalStateT (do replicateM iterations
 generateNormal) $ (Nothing,nextHalton) ) $ (1,[3,5])
  let stochastic = map (0.2*1*) normals
  let sde = map ((( 0.05 - (0.5*(0.2*0.2)) )*1)+) stochastic
  let expiryMult = map exp sde
  let expiry = map (100*) expiryMult
  let payoff = map (payOff 100) expiry
  let averagePO = (foldr (+) 0 payoff) / fromIntegral iterations
  let discountPO = averagePO * exp (-0.05)
  print discountPO


 * Common Code Used By Both Methods:


 import Control.Monad.State
 import Debug.Trace

 -- State Monad for QRNGs - stores current iteration and list of
 -- bases to compute
 type QuasiRandomState = State (Int,[Int])

 nextHalton :: QuasiRandomState [Double]
 nextHalton = do (n,bases) - get
let !nextN = n+1
put (nextN,bases)
return $ map (reflect (n,1,0)) bases

 type ReflectionThreadState = (Int,Double,Double)

 reflect :: ReflectionThreadState - Int - Double
 reflect (k,f,h) base
  | k = 0 = h
  | otherwise = reflect (newK,newF,newH) base
  where
newK = k `div` base
newF = f / fromIntegral base
newH = h + fromIntegral(k `mod` base) * newF

 -- So we are defining a state transform which has state of 'maybe double'
 and an
 -- operating function for the inner monad of type QuasiRandomMonad
 returning
 a [Double]
 -- We then say that it wraps an QuasiRandomMonad (State Monad) - it must of
 course
 -- if we pass it a function that operates on these Monads we must wrap the
 same
 -- type of Monad.  And finally it returns a double

 type BoxMullerStateT = StateT (Maybe Double, QuasiRandomState [Double])
 type BoxMullerQuasiState = BoxMullerStateT QuasiRandomState

 generateNormal :: BoxMullerQuasiState Double
 generateNormal = StateT $ \s - case s of
(Just d,qrnFunc) - return (d,(Nothing,qrnFunc))
(Nothing,qrnFunc) - do qrnBaseList - qrnFunc
let (norm1,norm2) = boxMuller (head
 qrnBaseList) (head $ tail qrnBaseList)

Re: [Haskell-cafe] Stacking State on State.....

2009-02-28 Thread Andrew Wagner
Ok, so this question of stacking state on top of state has come up several
times lately. So I decided to whip up a small example. So here's a goofy
little example of an abstract representation of a computer that can compute
a value of type 'a'. The two states here are a value of type 'a', and a
stack of functions of type (a-a) which can be applied to that value.
Disclaimer: this code is only type-checked, not tested!

import Control.Monad.State

-- first, we'll rename the type, for convenience
type Programmable a = StateT [a-a] (State a)

-- add a function to the stack of functions that can be applied
-- notice that we just use the normal State functions when dealing
-- with the first type of state
add :: (a - a) - Programmable a ()
add f = modify (f:)

-- add a bunch of functions to the stack
-- this time, notice that Programmable a is just a monad
addAll :: [a - a] - Programmable a ()
addAll = mapM_ add

-- this applies a function directly to the stored state, bypassing the
function stack
-- notice that, to use State functions on the second type of state, we must
use
-- lift to get to that layer
modify' :: (a - a) - Programmable a ()
modify' f = lift (modify f)

-- pop one function off the stack and apply it
-- notice again the difference between modify' and modify. we use modify' to
modify the value
-- and modify to modify the function stack. This is again because of the
order in which we wrapped
-- the two states. If we were dealing with StateT a (State [a-a]), it would
be the opposite.
step :: Programmable a ()
step = do
  fs - get
  let f = if (null fs) then id else (head fs)
  modify' f
  modify $ if (null fs) then id else (const (tail fs))

-- run the whole 'program'
runAll :: Programmable a ()
runAll = do
  fs - get
  if (null fs) then (return ()) else (step  runAll)

On Sat, Feb 28, 2009 at 8:31 AM, Daniel Fischer daniel.is.fisc...@web.dewrote:

 Am Samstag, 28. Februar 2009 13:23 schrieb Phil:
  Hi,
 
  The problem is ­ HOW DO I WRAP ANOTHER INDEPENDENT STATE AROUND THIS?
 
  After some googling it looked like the answer may be Monad Transformers.
  Specifically we could add a StateT transform for our Box Muller state to
  our VanDerCorput State Monad.
  Google didn¹t yield a direct answer here ­ so I¹m not even sure if my
  thinking is correct, people describe the process of using a transform as
  Œwrapping one monad in another¹ or Œthreading one monad into another¹.
  What we want to do is have some internal state controlled by an
 independent
  outer state -  this sounds about right to me?

 If you absolutely don't want to have a state describing both, yes.

 
  So I started playing around with the code, and got the below to compile.
 
  test ::  StateT (Bool,Double) (State Int) Double
  test = do (isStored,normal) - get
let (retNorm,storeNorm) = if isStored
  then (normal,0)
  else (n1,n2)
  where
n1 = 2
n2 = 3
put (not isStored, storeNorm)
return retNorm
 
  Now this is incomplete and may be even wrong!  I¹ll Explain my thinking:
 
  (Bool,Double) is equivalent to myState and storedNormal in the C example
  The last Double is the return value of the BoxMuller Monad
  The (State Int) is supposed to represent the VanDerCorput monad ­ but the
  compiler (GHC 6.10) will only let me specify one parameter with it ­ so
  I¹ve put the state and left the return type to the gods!! As I said
  this isn¹t quite right ­ any ideas how to specify the type?

 You can't, the second argument to StateT must be a Monad, hence a type
 constructor you can pass an arbitrary type which then produces a new type
 from that.
 Fortunately, you don't need to.

 Say you have

 type VDCMonad = State Int

 nextVDC :: VDCMonad Double
 nextVDC = do
n - get
put $! (n+1)
return $ calculateVDCFromInt n

 Then you could have

 boxMullerVDC :: StateT (Maybe Double) VDCMonad Double
 boxMullerVDC = StateT $ \s - case s of
Just d - return (d,Nothing)
Nothing - do
d1 - nextVDC
d2 - nextVDC
let (b1,b2) = boxMullerTransform d1
 d2
return (b1,Just b2)

 (I find a state of Maybe a more natural to indicate that *maybe* I have one
 a
 in store to use directly, than using (Bool,a)).

 However, I suspect that you would get better code if you abstracted over
 the
 sequence of pseudorandom Doubles and had simply

 calculation :: Sate [Double] whatever
 calculation = ???

 result = evalState calculation bmVDC

 bmVDC = boxMuller $ map vanDerCorput [1 .. ]
where
boxMuller (k:n:more) = u:v:boxMuller more
where
 

Re: [Haskell-cafe] Stacking State on State.....

2009-02-28 Thread Andrew Wagner
Thanks for helping clean up my dirty little hacking. This could  
actually be made nicer by defining the following, and rewriting the  
original code in terms of it:


type State2 a b = StateT a (State b)
type Programmable a = State2 a (a-a)

I'll leave the rewrite as an exercise for the reader, since I'm  
standing in the store writing this on my iPhone :)



On Feb 28, 2009, at 10:08 AM, Daniel Fischer  
daniel.is.fisc...@web.de wrote:



Am Samstag, 28. Februar 2009 15:36 schrieb Andrew Wagner:
Ok, so this question of stacking state on top of state has come up  
several
times lately. So I decided to whip up a small example. So here's a  
goofy
little example of an abstract representation of a computer that can  
compute
a value of type 'a'. The two states here are a value of type 'a',  
and a

stack of functions of type (a-a) which can be applied to that value.


Nice.


Disclaimer: this code is only type-checked, not tested!

import Control.Monad.State


import Control.Moand (unless)



-- first, we'll rename the type, for convenience
type Programmable a = StateT [a-a] (State a)

-- add a function to the stack of functions that can be applied
-- notice that we just use the normal State functions when dealing
-- with the first type of state
add :: (a - a) - Programmable a ()
add f = modify (f:)

-- add a bunch of functions to the stack
-- this time, notice that Programmable a is just a monad
addAll :: [a - a] - Programmable a ()
addAll = mapM_ add


Be aware that this adds the functions in reverse order, an  
alternative is


addAll = modify . (++)

(addAll fs = modify (fs ++))



-- this applies a function directly to the stored state, bypassing  
the

function stack
-- notice that, to use State functions on the second type of state,  
we must

use
-- lift to get to that layer
modify' :: (a - a) - Programmable a ()
modify' f = lift (modify f)

-- pop one function off the stack and apply it
-- notice again the difference between modify' and modify. we use  
modify'

to modify the value
-- and modify to modify the function stack. This is again because  
of the

order in which we wrapped
-- the two states. If we were dealing with StateT a (State [a-a]),  
it

would be the opposite.
step :: Programmable a ()
step = do
 fs - get
 let f = if (null fs) then id else (head fs)
 modify' f
 modify $ if (null fs) then id else (const (tail fs))


Last line could be

modify (drop 1)



-- run the whole 'program'
runAll :: Programmable a ()
runAll = do
 fs - get
 if (null fs) then (return ()) else (step  runAll)


runAll = do
   stop - gets null
   unless stop (step  runAll)



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


Re: [Haskell-cafe] Stacking State on State.....

2009-02-28 Thread Andrew Wagner
Heh. Actually, there is no more rewrite. But I muffed the second definition:
it should, of course be:

type Programmable a = State2 [a-a] a

On Sat, Feb 28, 2009 at 10:35 AM, Andrew Wagner wagner.and...@gmail.comwrote:

 Thanks for helping clean up my dirty little hacking. This could actually be
 made nicer by defining the following, and rewriting the original code in
 terms of it:

 type State2 a b = StateT a (State b)
 type Programmable a = State2 a (a-a)

 I'll leave the rewrite as an exercise for the reader, since I'm standing in
 the store writing this on my iPhone :)



 On Feb 28, 2009, at 10:08 AM, Daniel Fischer daniel.is.fisc...@web.de
 wrote:

  Am Samstag, 28. Februar 2009 15:36 schrieb Andrew Wagner:

 Ok, so this question of stacking state on top of state has come up
 several
 times lately. So I decided to whip up a small example. So here's a goofy
 little example of an abstract representation of a computer that can
 compute
 a value of type 'a'. The two states here are a value of type 'a', and a
 stack of functions of type (a-a) which can be applied to that value.


 Nice.

  Disclaimer: this code is only type-checked, not tested!

 import Control.Monad.State


 import Control.Moand (unless)


 -- first, we'll rename the type, for convenience
 type Programmable a = StateT [a-a] (State a)

 -- add a function to the stack of functions that can be applied
 -- notice that we just use the normal State functions when dealing
 -- with the first type of state
 add :: (a - a) - Programmable a ()
 add f = modify (f:)

 -- add a bunch of functions to the stack
 -- this time, notice that Programmable a is just a monad
 addAll :: [a - a] - Programmable a ()
 addAll = mapM_ add


 Be aware that this adds the functions in reverse order, an alternative is

 addAll = modify . (++)

 (addAll fs = modify (fs ++))


 -- this applies a function directly to the stored state, bypassing the
 function stack
 -- notice that, to use State functions on the second type of state, we
 must
 use
 -- lift to get to that layer
 modify' :: (a - a) - Programmable a ()
 modify' f = lift (modify f)

 -- pop one function off the stack and apply it
 -- notice again the difference between modify' and modify. we use modify'
 to modify the value
 -- and modify to modify the function stack. This is again because of the
 order in which we wrapped
 -- the two states. If we were dealing with StateT a (State [a-a]), it
 would be the opposite.
 step :: Programmable a ()
 step = do
  fs - get
  let f = if (null fs) then id else (head fs)
  modify' f
  modify $ if (null fs) then id else (const (tail fs))


 Last line could be

 modify (drop 1)


 -- run the whole 'program'
 runAll :: Programmable a ()
 runAll = do
  fs - get
  if (null fs) then (return ()) else (step  runAll)


 runAll = do
   stop - gets null
   unless stop (step  runAll)



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


Re: [Haskell-cafe] Left fold enumerator - a real pearl overlooked?

2009-02-28 Thread Andrew Wagner
Can someone point us to some resources about these? I for one have not heard
of them before

On Sat, Feb 28, 2009 at 12:59 PM, Johan Tibell johan.tib...@gmail.comwrote:

 On Sat, Feb 28, 2009 at 5:08 PM, Gü?nther Schmidt gue.schm...@web.de
 wrote:
  Hi all,
 
  in the last few months I was looking for haskell database library,
  eventually settling for HDBC (thanks John btw).
 
  Takusen also caught my eye although I even failed installing it.
 
  Nevertheless a particular property of takusen, left-fold-enumerator, also
  sparked  my interest and I tried to follow it up.
 
  I had the impression this is something of relevance but something that is
  not mentioned or made use of often. There are actually only a few
 references
  on the net and most of those by one person only, Oleg.
 
  There was one post from John Goerzen about Haskell HTTP libraries in
 which
  he hinted using left-fold enumerators.
 
  Anyway what I'm saying is that the whole topic is somewhat off the radar
 of
  the larger haskell community, how come, or am I merely overestimating its
  relevance and usefulness?

 A couple of people (me included) have been discussing different
 possible designs outside this mailing list. I think we're getting a
 better understanding of the design space but I feel like there's more
 to be discovered which is probably the reason none of us have release
 a library that makes use of left fold enumerators.

 Cheers,

 Johan
 ___
 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] Haskellers on Twitter!

2009-02-23 Thread Andrew Wagner
Modified. Is this how you want it to show?

2009/2/23 Brandon S. Allbery KF8NH allb...@ece.cmu.edu

 On 2009 Feb 21, at 16:14, Daniel Peebles wrote:

 http://haskell.org/haskellwiki/Twitter. Please update with yourself or
 any other Haskellers we may have missed.



 Since I can't create an account to fix my entry:
 (1) my name is misspelled
 (2) partly to synchronize my accounts and partly to try to figure out why
 searches for me on http://search.twitter.com fail, I changed my account
 name.

 If you're looking to follow me on Twitter, I'm now geekosaur.  (I still
 don't show up in searches though.  One of many; the folks at Twitter seem to
 have trouble with getting their indexes to work right)

 --
 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



 ___
 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] How to create an online poll

2009-02-18 Thread Andrew Wagner
Just wrap it in a ReallySafeWePromiseMonad

2009/2/18 gregg reynolds d...@mobileink.com

 I.e. war, plague.famine. etc.

 gregg reynolds d...@mobileink.com wrote:

 But what about the side effects?
 
 Rick R rick.richard...@gmail.com wrote:
 
 I'm sure Premier Election Solutions (formerly Diebold) can provide us
 with
 an online voting solution.
 Their value-add services allows us to set the outcome beforehand, so, in
 effect, the the voting process will be determinate. Which is certainly of
 interest to Haskell coders.
 
 
 On Wed, Feb 18, 2009 at 4:05 PM, Max Rabkin max.rab...@gmail.com
 wrote:
 
  On Wed, Feb 18, 2009 at 10:40 PM, Anton van Straaten
  an...@appsolutions.com wrote:
   There's also the Condorcet Internet Voting Service:
  
http://www.cs.cornell.edu/andru/civs.html
 
  This looks like exactly what we need! Any objections?
 
  --Max
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 
 
 
 --
 We can't solve problems by using the same kind of thinking we used when
 we
 created them.
- A. Einstein
 ___
 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] How to create an online poll

2009-02-18 Thread Andrew Wagner
Sure it will. Don't worry, it uses unsafePerformIO under the hood, so it's
pretty much indestructible.

On Wed, Feb 18, 2009 at 4:47 PM, gregg reynolds d...@mobileink.com wrote:

 Ok, that might protect us against the 7 plagues, so I'm not so worried
 about locusts.  But what about Java, PHP etc.  Is the monad sufficient
 protection against ultra-supernatural evil?

 Andrew Wagner wagner.and...@gmail.com wrote:

 Just wrap it in a ReallySafeWePromiseMonad
 
 2009/2/18 gregg reynolds d...@mobileink.com
 
  I.e. war, plague.famine. etc.
 
  gregg reynolds d...@mobileink.com wrote:
 
  But what about the side effects?
  
  Rick R rick.richard...@gmail.com wrote:
  
  I'm sure Premier Election Solutions (formerly Diebold) can provide us
  with
  an online voting solution.
  Their value-add services allows us to set the outcome beforehand, so,
 in
  effect, the the voting process will be determinate. Which is certainly
 of
  interest to Haskell coders.
  
  
  On Wed, Feb 18, 2009 at 4:05 PM, Max Rabkin max.rab...@gmail.com
  wrote:
  
   On Wed, Feb 18, 2009 at 10:40 PM, Anton van Straaten
   an...@appsolutions.com wrote:
There's also the Condorcet Internet Voting Service:
   
 http://www.cs.cornell.edu/andru/civs.html
  
   This looks like exactly what we need! Any objections?
  
   --Max
   ___
   Haskell-Cafe mailing list
   Haskell-Cafe@haskell.org
   http://www.haskell.org/mailman/listinfo/haskell-cafe
  
  
  
  
  --
  We can't solve problems by using the same kind of thinking we used
 when
  we
  created them.
 - A. Einstein
  ___
  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] How to create an online poll

2009-02-18 Thread Andrew Wagner

Help! Help! I'm being suppressed!!

On Feb 18, 2009, at 5:05 PM, Rick R rick.richard...@gmail.com wrote:

I can't comment on any quantitative side effects, but the some  
intangible side effects include Distrustful Populace and  
MaliciousDissenters. However, if ghc is run with the - 
XUnscrupulousPolitics  flag, those can be suppressed.


On Wed, Feb 18, 2009 at 4:33 PM, gregg reynolds d...@mobileink.com  
wrote:

I.e. war, plague.famine. etc.

gregg reynolds d...@mobileink.com wrote:

But what about the side effects?

Rick R rick.richard...@gmail.com wrote:

I'm sure Premier Election Solutions (formerly Diebold) can provide  
us with

an online voting solution.
Their value-add services allows us to set the outcome beforehand,  
so, in
effect, the the voting process will be determinate. Which is  
certainly of

interest to Haskell coders.


On Wed, Feb 18, 2009 at 4:05 PM, Max Rabkin max.rab...@gmail.com  
wrote:


 On Wed, Feb 18, 2009 at 10:40 PM, Anton van Straaten
 an...@appsolutions.com wrote:
  There's also the Condorcet Internet Voting Service:
 
   http://www.cs.cornell.edu/andru/civs.html

 This looks like exactly what we need! Any objections?

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




--
We can't solve problems by using the same kind of thinking we used  
when we

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



--
We can't solve problems by using the same kind of thinking we used  
when we created them.

   - A. Einstein
___
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] Re: [Haskell-cafe] ANN: The Typeclassopedia, and request for feedback

2009-02-16 Thread Andrew Wagner
Positively brilliant. What else can be said? Time for Brent to sign a
Haskell recipes deal with O'Reilly (or whatever the next normal book
should be).

On Mon, Feb 16, 2009 at 4:29 AM, Brent Yorgey byor...@seas.upenn.eduwrote:

 Hi all,

 If you've noticed the lack of a HWN this week, that's because I've
 been doggedly finishing my article entitled 'The Typeclassopedia',
 which I have just submitted for publication in the Monad.Reader.
 Here's the abstract:

The standard Haskell libraries feature a number of type classes
with algebraic or categorical underpinnings. Becoming a fluent
Haskell hacker requires intimate familiarity with them all, yet
acquiring this familiarity often involves combing through a
mountain of tutorials, blog posts, mailing list archives, and IRC
logs.

The goal of this article is to serve as a starting point for the
student of Haskell wishing to gain a firm grasp of its standard
type classes. The essentials of each type class are introduced,
with examples, commentary, and extensive references for further
reading.

 My hope is that this will be a valuable resource to the Haskell
 community, especially those who are learning.  Any feedback would be
 greatly appreciated, especially if it helps improve the article before
 publication.  A draft can be found here:


 http://www.cis.upenn.edu/~byorgey/papers/typeclassopedia-draft-090216.pdf

 Also see my blog post for a bit more info:


 http://byorgey.wordpress.com/2009/02/16/the-typeclassopedia-request-for-feedback/

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

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


Re: [Haskell-cafe] ANN: The Typeclassopedia, and request for feedback

2009-02-16 Thread Andrew Wagner
Positively brilliant. What else can be said? Time for Brent to sign a
Haskell recipes deal with O'Reilly (or whatever the next normal book
should be).

On Mon, Feb 16, 2009 at 4:29 AM, Brent Yorgey byor...@seas.upenn.eduwrote:

 Hi all,

 If you've noticed the lack of a HWN this week, that's because I've
 been doggedly finishing my article entitled 'The Typeclassopedia',
 which I have just submitted for publication in the Monad.Reader.
 Here's the abstract:

The standard Haskell libraries feature a number of type classes
with algebraic or categorical underpinnings. Becoming a fluent
Haskell hacker requires intimate familiarity with them all, yet
acquiring this familiarity often involves combing through a
mountain of tutorials, blog posts, mailing list archives, and IRC
logs.

The goal of this article is to serve as a starting point for the
student of Haskell wishing to gain a firm grasp of its standard
type classes. The essentials of each type class are introduced,
with examples, commentary, and extensive references for further
reading.

 My hope is that this will be a valuable resource to the Haskell
 community, especially those who are learning.  Any feedback would be
 greatly appreciated, especially if it helps improve the article before
 publication.  A draft can be found here:


 http://www.cis.upenn.edu/~byorgey/papers/typeclassopedia-draft-090216.pdf

 Also see my blog post for a bit more info:


 http://byorgey.wordpress.com/2009/02/16/the-typeclassopedia-request-for-feedback/

 happy haskelling!
 -Brent
 ___
 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] Another point-free question (=, join, ap)

2009-02-12 Thread Andrew Wagner
Check out liftM2. It's almost what you want.

On Thu, Feb 12, 2009 at 6:36 PM, Edsko de Vries devri...@cs.tcd.ie wrote:

 Hi,

 I can desugar

  do x' - x
 f x'

 as

  x = \x - f x'

 which is clearly the same as

  x = f

 However, now consider

  do x' - x
 y' - y
 f x' y'

 desugared, this is

  x = \x - y = \y' - f x' y'

 I can simplify the second half to

  x = \x - y = f x'

 but now we are stuck. I feel it should be possible to write something like

  x ... y ... f

 or perhaps

  f ... x ... y

 the best I could come up with was

  join $ return f `ap` x `ap` y

 which is not terrible but quite as easy as I feel this should be. Any
 hints?

 Edsko
 ___
 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] Is this related to continuations somehow?

2009-02-12 Thread Andrew Wagner
So, I was reading a bit about continuations the other day, and, since I've
been thinking about good ways of expressing chess strategies in Haskell, I
thought that I'd play around a bit with something like continuations for
game-playing strategies. The idea is that you have combinators that allow
you full access to the strategies which remain to be applied. In this way,
strategies can activate and de-activate other strategies. Here's a
simple little toy app for Tic-Tac-Toe (Naughts and Crosses):

http://codepad.org/nN9JsxFK

You can run main on 'example', and see that it searches every line and
fails. And, as you can see, it aborts after finding a win in example2. This
would be easily extensible to say things like if you've seen a blocking
move, and you don't have a win, then play the blocking move, and of course
the other deep intricacies of the game.

My question is, is this, in fact, related to continuations somehow? Could
continuations simplify it? Or am I doing something completely different?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Control.Arrow being icky

2009-02-09 Thread Andrew Wagner
It's spelled 'Kleisli'. You spelled it 'Kliesli'

2009/2/9 Louis Wasserman wasserman.lo...@gmail.com

 In GHCi, I import Control.Arrow, and Kliesli doesn't appear:
 Prelude Control.Arrow :t Kliesli

 interactive:1:0: Not in scope: data constructor `Kliesli'
 Prelude Control.Arrow :browse
 (^) :: (Arrow a) = a c d - (b - c) - a b d
 (^) :: (Arrow a) = a b c - (c - d) - a b d
 class (Control.Category.Category a) = Arrow a where
   arr :: (b - c) - a b c
   first :: a b c - a (b, d) (c, d)
   second :: a b c - a (d, b) (d, c)
   (***) :: a b c - a b' c' - a (b, b') (c, c')
   () :: a b c - a b c' - a b (c, c')
 class (Arrow a) = ArrowApply a where app :: a (a b c, b) c
 class (Arrow a) = ArrowChoice a where
   left :: a b c - a (Either b d) (Either c d)
   right :: a b c - a (Either d b) (Either d c)
   (+++) :: a b c - a b' c' - a (Either b b') (Either c c')
   (|||) :: a b d - a c d - a (Either b c) d
 class (Arrow a) = ArrowLoop a where
   loop :: a (b, d) (c, d) - a b c
 newtype (ArrowApply a) = ArrowMonad a b = ArrowMonad (a () b)
 class (ArrowZero a) = ArrowPlus a where
   (+) :: a b c - a b c - a b c
 class (Arrow a) = ArrowZero a where zeroArrow :: a b c
 newtype Kleisli m a b = Kleisli {runKleisli :: a - m b}
 (^) :: (Arrow a) = (c - d) - a b c - a b d
 (^) :: (Arrow a) = (b - c) - a c d - a b d
 leftApp :: (ArrowApply a) = a b c - a (Either b d) (Either c d)
 returnA :: (Arrow a) = a b b
 () ::
   (Control.Category.Category cat) = cat b c - cat a b - cat a c
 () ::
   (Control.Category.Category cat) = cat a b - cat b c - cat a c

 Does anybody know what's going on?

 Louis Wasserman
 wasserman.lo...@gmail.com

 ___
 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] Haskell Fest

2009-02-09 Thread Andrew Wagner
We believe in Haskell!

2009/2/9 Lyle Kopnicky li...@qseep.net

 Looks like a lot of fun!

 http://www.haskellchamber.com/page6.html

 ___
 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] The Haskell re-branding exercise

2009-02-07 Thread Andrew Wagner
 We need a voting site set up. There was some progress prior to the end
 of the year. Updates welcome!

 -- Don


Can't we just use the haskell proposal reddit for this?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] The Haskell re-branding exercise

2009-02-07 Thread Andrew Wagner
Um, ok. Glad we could discuss it

On Sat, Feb 7, 2009 at 1:12 PM, Don Stewart d...@galois.com wrote:

 wagner.andrew:
 
  We need a voting site set up. There was some progress prior to the
 end
  of the year. Updates welcome!
 
  -- Don
 
  Can't we just use the haskell proposal reddit for this?

 Hmm... not ideal. Would make a backup should all else fail.



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


Re: [Haskell-cafe] Re: evaluation semantics of bind

2009-02-05 Thread Andrew Wagner
Are you saying that using equations to add a level of indirection
 prevents optimization?  I still don't see it - discarding x doesn't
 change the semantics, so a good compiler /should/ do this.  How is
 this different from optimizing out application of a constant function?


No, no compiler should change getChar = \x - getChar to just getChar,
because it's just wrong. The first will try to read in two values of type
Char, the second will only try to read one. Side effects aren't THAT hated!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad explanation

2009-02-05 Thread Andrew Wagner

 I think the point of the Monad is that it works as a container of stuff,
 that still allows mathematically pure things to happen, while possibly
 having some opaque other stuff going on.


 This at least sounds, very wrong, even if it's not. Monads are not impure.
IO is, but it's only _one_ instance of Monad. All others, as far as I know,
are pure. It's just that the bind operation allows you to hide the stuff you
don't want to have to worry about, that should happen every time you compose
two monadic actions.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad explanation

2009-02-05 Thread Andrew Wagner
On Thu, Feb 5, 2009 at 3:21 PM, David Leimbach leim...@gmail.com wrote:


 Well all I can tell you is that I can have (IO Int) in a function as a
 return, and the function is not idempotent in terms of the stuff inside IO
 being the same.

 Sounds impure to me.


Right, thus IO is impure. but as long as the function that returns the IO
Int returns the same IO Int every time you provide the same input, it's
pure.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Bind as a sequencing operator

2009-02-05 Thread Andrew Wagner
bind is no more a sequencing operator than function composition is. Just as
the order in which you pass two functions (ignoring the type issue for the
moment) matters, the order in which you pass things to bind matters. The
sense in which the order _doesn't_ matter is that of the order in which what
you pass gets evaluated.

On Thu, Feb 5, 2009 at 3:32 PM, Jake McArthur j...@pikewerks.com wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 m...@justinbogner.com wrote:
 | Jake McArthur j...@pikewerks.com writes:
 | The problem with your description is that you said and then. The
 | result will be generated lazily. There is no sequencing here. Consider:
 |
 | ~do x - [0..]
 | ~   y - [0..9]
 | ~   return (x, y)
 |
 | Which list is generated first?
 |
 |
 | This is an implementation detail, since y has no dependency on x the
 | compiler's free to reorder instructions, as it would be an imperative
 | language. Semantically this means do x and then y

 That the order does not matter is definitely not an implementation
 detail. Order not mattering is exactly what declarative programming is
 about. The semantics of the above expression are the same as this:

 ~($ [0..9]) . (,) = [0..]

 There is no do X and then do Y, only this is what I want.
 Declarative semantics. As I said, just because do notation makes it look
 imperative doesn't mean it actually is.

 | Just because the compiler is allowed (and even encouraged) to change the
 | sequence where that won't change the results, considering this a
 | sequence is still valid and meaningful.

 It can be helpful sometimes, but I don't think it should be the standard
 way to think of bind. There are too many cases when it makes little
 sense as a sequencing operator.

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

 iEYEARECAAYFAkmLTPEACgkQye5hVyvIUKkoCACgz/IYvxa6PoEvuqgxljGAwZ8+
 TXQAn30MyLDwhLyZV3+dRuJvttx93ZNh
 =P9em
 -END PGP SIGNATURE-
 ___
 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] Just how unsafe is unsafe

2009-02-05 Thread Andrew Wagner
So we all know the age-old rule of thumb, that unsafeXXX is simply evil and
anybody that uses it should be shot (except when it's ok).
I understand that unsafeXXX allows impurity, which defiles our ability to
reason logically about haskell programs like we would like to. My question
is, to what extent is this true?

Suppose we had a module, UnsafeRandoms, which had a function that would
allow you to generate a different random number every time you call it. The
semantics are relatively well-defined, impurity is safely sectioned off in
its own impure module, which is clearly labeled as such. How much damage
does this do?

Can we push the lines elsewhere? Is sectioning unsafeXXX into Unsafe modules
a useful idiom that we can use for other things as well?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad explanation

2009-02-04 Thread Andrew Wagner
This is nice and simple. My only concern is I'm not sure there's enough of a
distinction between Monad and State Monad. That is, I'm not sure it's
clear enough that the way you're binding the small programs together in the
initial example is only one way you could bind them together, and thus it's
only one instance of Monad.

On Wed, Feb 4, 2009 at 12:41 PM, Tim Newsham news...@lava.net wrote:

 I put up a small Monad explanation (I wouldn't quite call it
 a tutorial):
  http://www.thenewsh.com/~newsham/haskell/monad.html

 The intent here is to is to have a short description of what
 a Monad is that is approachable by Haskell beginners or non-
 Haskell programmers who are looking for an intuitive definition
 but may not yet have the background or the inclination to
 jump into full tutorial to tackle the subject.

 Tim Newsham
 http://www.thenewsh.com/~newsham/
 ___
 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] Re: [Haskell-cafe] ANN: #haskell-in-depth IRC channel

2009-02-03 Thread Andrew Wagner
Well-done! I've said for many months that we need a channel like this!

On Tue, Feb 3, 2009 at 7:15 PM, Philippa Cowderoy fli...@flippac.orgwrote:

 Hi folks. As I've been daft enough to get a few things rolling, it looks
 like it's fallen on me to announce the new IRC channel,
 #haskell-in-depth.

 #haskell has been a roaring success over the last few years, as Don has
 repeatedly pointed out. Unfortunately that roar is starting to make it
 hard for some to participate - there's so much traffic that it can be
 difficult to fit an additional conversation in. We're starting to hit
 the limits as to how far one channel can take us, and that means we need
 to explore ways to divide up traffic.

 Actually, this isn't entirely new - a number of years ago now,
 #haskell-blah was formed as a space for off-topic (and sometimes
 less-than-worksafe) conversation among #haskell regulars. We also
 created #haskell-overflow, but it doesn't see much use except among some
 of the cabal implementors because it's hard to know when to take the
 conversation you're currently in to -overflow.

 We need channels that people start their conversations in, not ones to
 send people to! So we're trying a space for in-depth discussion. The new
 channel is open to everyone, just like #haskell. But just as we're
 hoping for certain kinds of discussion, there're others we want to
 avoid. If you need to know how to use monads so you can do IO,
 #haskell-in-depth isn't the place. On the other hand, if you want to
 discuss how Haskell's monads compare to the category theory or what the
 category theory can tell us about how individual monads relate to the
 language as a whole, -in-depth is a good place! In particular, we're
 hoping that the kind of category theory discussions that give the
 mistaken impression you actually need to know CT will increasingly live
 in #haskell-in-depth.

 We're not after a theory channel though - architectural discussion,
 compiler implementation, possible type system extensions, library
 design, all are good subjects.

 Anyway, I shouldn't ramble on for too long here - #haskell-in-depth is
 open for business and we look forward to seeing you there!

 --
 Philippa Cowderoy fli...@flippac.org

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

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


Re: [Haskell-cafe] Converting Lists to Sets

2009-02-03 Thread Andrew Wagner
Actually, a list of list of literals is needed, since it's a Set Clause, and
a Clause is a [Literal].

On Tue, Feb 3, 2009 at 5:24 PM, Robin Green gree...@greenrd.org wrote:

 On Tue, 3 Feb 2009 19:58:51 -0200
 rodrigo.bonifacio rodrigo.bonifa...@uol.com.br wrote:

  Hi all,
 
  I'm trying to use the Funsat library. One of its data types is CNF:
 
  data CNF = CNF {
   numVars :: Int
   numClauses :: Int
   clauses :: Set Clause
  }
 
  I have a list of clauses, but I'm getting an error when converting
  such a list to a Set. Using the fromList function, the ghc compiler
  reports that the fromList function is not applicable to literals.
 
  type Clause = [Lit]
 
  newtype Lit = L {
   unLit :: Int
  }
 

 You don't provide your code or the exact error message, which makes
 it harder to diagnose - but I'd guess you are mistakenly trying to apply
 fromList to a *single* literal, rather than a *list* of literals.
 --
 Robin
 ___
 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] ANN: #haskell-in-depth IRC channel

2009-02-03 Thread Andrew Wagner
Well-done! I've said for many months that we need a channel like this!

On Tue, Feb 3, 2009 at 7:15 PM, Philippa Cowderoy fli...@flippac.orgwrote:

 Hi folks. As I've been daft enough to get a few things rolling, it looks
 like it's fallen on me to announce the new IRC channel,
 #haskell-in-depth.

 #haskell has been a roaring success over the last few years, as Don has
 repeatedly pointed out. Unfortunately that roar is starting to make it
 hard for some to participate - there's so much traffic that it can be
 difficult to fit an additional conversation in. We're starting to hit
 the limits as to how far one channel can take us, and that means we need
 to explore ways to divide up traffic.

 Actually, this isn't entirely new - a number of years ago now,
 #haskell-blah was formed as a space for off-topic (and sometimes
 less-than-worksafe) conversation among #haskell regulars. We also
 created #haskell-overflow, but it doesn't see much use except among some
 of the cabal implementors because it's hard to know when to take the
 conversation you're currently in to -overflow.

 We need channels that people start their conversations in, not ones to
 send people to! So we're trying a space for in-depth discussion. The new
 channel is open to everyone, just like #haskell. But just as we're
 hoping for certain kinds of discussion, there're others we want to
 avoid. If you need to know how to use monads so you can do IO,
 #haskell-in-depth isn't the place. On the other hand, if you want to
 discuss how Haskell's monads compare to the category theory or what the
 category theory can tell us about how individual monads relate to the
 language as a whole, -in-depth is a good place! In particular, we're
 hoping that the kind of category theory discussions that give the
 mistaken impression you actually need to know CT will increasingly live
 in #haskell-in-depth.

 We're not after a theory channel though - architectural discussion,
 compiler implementation, possible type system extensions, library
 design, all are good subjects.

 Anyway, I shouldn't ramble on for too long here - #haskell-in-depth is
 open for business and we look forward to seeing you there!

 --
 Philippa Cowderoy fli...@flippac.org

 ___
 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] Fold that quits early?

2009-01-24 Thread Andrew Wagner
This is almost a fold, but seemingly not quite? I know I've seem some talk
of folds that potentially quit early. but not sure where I saw that, or if
it fits.

f xs [] = False
f xs (y:ys) | any c ys' = True
| otherwise = f (nub (y:xs)) (ys' ++ ys)
   where ys' = g y xs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Fold that quits early?

2009-01-24 Thread Andrew Wagner
Actually, I think I can rewrite it this way:

f xs [] = False
f xs (y:ys) | any c ys' = True
| otherwise = f (f (y:xs) ys') ys
  where ys' = g y ys

This should help, I think.

On Sat, Jan 24, 2009 at 12:11 PM, Dan Doel dan.d...@gmail.com wrote:

 On Saturday 24 January 2009 11:39:13 am Andrew Wagner wrote:
  This is almost a fold, but seemingly not quite? I know I've seem some
 talk
  of folds that potentially quit early. but not sure where I saw that, or
  if it fits.
 
  f xs [] = False
  f xs (y:ys) | any c ys' = True
 
  | otherwise = f (nub (y:xs)) (ys' ++ ys)
 
 where ys' = g y xs

 Quitting early isn't the problem. For instance, any is defined in terms of
 foldr, and it works fine on infinite lists, quitting as soon as it finds a
 True. As long as you don't use the result of the recursive call (which is
 the
 second argument in the function you pass to foldr), it will exit early.

 The problem is that your function doesn't look structurally recursive, and
 that's what folds (the usual ones, anyway) are: a combinator for structural
 recursion. The problem is in your inductive case, where you don't just
 recurse
 on ys, you instead recurse on ys' ++ ys, where ys' is the result of an
 arbitrary function. folds simply don't work that way, and only give you
 access
 to the recursive call over the tail, but in a language like Agda, the
 termination checker would flag even this definition, and you'd have to, for
 instance, write a proof that this actually does terminate, and do induction
 on
 the structure of the proof, or use some other such technique for writing
 non-
 structurally recursive functions.

 -- Dan

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


Re: [Haskell-cafe] Fold that quits early?

2009-01-24 Thread Andrew Wagner
Ahem. That's what happens when you don't type-check your brainstorming
before barfing it out, kids. Sorry about that. Let's try this again:

f _ [] = []
f y x | c y = []
| otherwise = foldr f (y:x) (g y x)

I've got a fold on the inside now, but I'm pretty sure the whole thing is
just a fold. Not quite there yet, though...

On Sat, Jan 24, 2009 at 1:42 PM, Andrew Wagner wagner.and...@gmail.comwrote:

 Actually, I think I can rewrite it this way:

 f xs [] = False
 f xs (y:ys) | any c ys' = True
 | otherwise = f (f (y:xs) ys') ys
   where ys' = g y ys

 This should help, I think.


 On Sat, Jan 24, 2009 at 12:11 PM, Dan Doel dan.d...@gmail.com wrote:

 On Saturday 24 January 2009 11:39:13 am Andrew Wagner wrote:
  This is almost a fold, but seemingly not quite? I know I've seem some
 talk
  of folds that potentially quit early. but not sure where I saw that,
 or
  if it fits.
 
  f xs [] = False
  f xs (y:ys) | any c ys' = True
 
  | otherwise = f (nub (y:xs)) (ys' ++ ys)
 
 where ys' = g y xs

 Quitting early isn't the problem. For instance, any is defined in terms of
 foldr, and it works fine on infinite lists, quitting as soon as it finds a
 True. As long as you don't use the result of the recursive call (which is
 the
 second argument in the function you pass to foldr), it will exit early.

 The problem is that your function doesn't look structurally recursive, and
 that's what folds (the usual ones, anyway) are: a combinator for
 structural
 recursion. The problem is in your inductive case, where you don't just
 recurse
 on ys, you instead recurse on ys' ++ ys, where ys' is the result of an
 arbitrary function. folds simply don't work that way, and only give you
 access
 to the recursive call over the tail, but in a language like Agda, the
 termination checker would flag even this definition, and you'd have to,
 for
 instance, write a proof that this actually does terminate, and do
 induction on
 the structure of the proof, or use some other such technique for writing
 non-
 structurally recursive functions.

 -- Dan



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


Re: [Haskell-cafe] Fold that quits early?

2009-01-24 Thread Andrew Wagner
There's at least one thing; I won't call it a flaw in your logic, but it's
not true of my usage. Your definition always produces a non-null list. The
particular g in my mind will eventually produce a null list, somewhere down
the line. I think if that's true, we can guarantee termination.

On Sat, Jan 24, 2009 at 10:16 PM, Ryan Ingram ryani.s...@gmail.com wrote:

 foldr f z xs =
   x0 `f` (x1 `f` (x2 `f` ... (xN `f` z) ...))

 In particular, note that if f is a total function, xs is finite and
 totally defined, and z is totally defined, then the result of this
 fold is totally defined.

 Now consider your f (rewritten slightly)

 f x xs
   | null xs = []
   | p x = []
   | otherwise = foldr f (x:xs) (g x xs)

 with these definitions:

 c _ = False
 g = (:)

 c and g are definitely total functions, so what happens when we
 evaluate f 0 [1]?

 f 0 [1]
= foldr f [0,1] [0,1]
= let t1 = foldr f [0,1] [1] in f 0 $ t1
= let t1 = foldr f [0,1] [1] in foldr f (0 : t1) (0 : t1)
= let t1 = foldr f [0,1] [1]
  t2 = foldr f (0:t1) t1
  in f 0 t2

 etc.; this is clearly non-terminating.

 Therefore there is no way to make f into a fold.

 Any errors in my logic?

  -- ryan

 2009/1/24 Andrew Wagner wagner.and...@gmail.com:
  Ahem. That's what happens when you don't type-check your brainstorming
  before barfing it out, kids. Sorry about that. Let's try this again:
 
  f _ [] = []
  f y x | c y = []
  | otherwise = foldr f (y:x) (g y x)
 
  I've got a fold on the inside now, but I'm pretty sure the whole thing is
  just a fold. Not quite there yet, though...
 
  On Sat, Jan 24, 2009 at 1:42 PM, Andrew Wagner wagner.and...@gmail.com
  wrote:
 
  Actually, I think I can rewrite it this way:
 
  f xs [] = False
  f xs (y:ys) | any c ys' = True
  | otherwise = f (f (y:xs) ys') ys
where ys' = g y ys
 
  This should help, I think.
 
  On Sat, Jan 24, 2009 at 12:11 PM, Dan Doel dan.d...@gmail.com wrote:
 
  On Saturday 24 January 2009 11:39:13 am Andrew Wagner wrote:
   This is almost a fold, but seemingly not quite? I know I've seem some
   talk
   of folds that potentially quit early. but not sure where I saw
 that,
   or
   if it fits.
  
   f xs [] = False
   f xs (y:ys) | any c ys' = True
  
   | otherwise = f (nub (y:xs)) (ys' ++ ys)
  
  where ys' = g y xs
 
  Quitting early isn't the problem. For instance, any is defined in terms
  of
  foldr, and it works fine on infinite lists, quitting as soon as it
 finds
  a
  True. As long as you don't use the result of the recursive call (which
 is
  the
  second argument in the function you pass to foldr), it will exit early.
 
  The problem is that your function doesn't look structurally recursive,
  and
  that's what folds (the usual ones, anyway) are: a combinator for
  structural
  recursion. The problem is in your inductive case, where you don't just
  recurse
  on ys, you instead recurse on ys' ++ ys, where ys' is the result of
  an
  arbitrary function. folds simply don't work that way, and only give you
  access
  to the recursive call over the tail, but in a language like Agda, the
  termination checker would flag even this definition, and you'd have to,
  for
  instance, write a proof that this actually does terminate, and do
  induction on
  the structure of the proof, or use some other such technique for
 writing
  non-
  structurally recursive functions.
 
  -- Dan
 
 
 
  ___
  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] Fold that quits early?

2009-01-24 Thread Andrew Wagner
Ok, maybe let's make this a little more concrete. I'm trying to write
forward-chaining logical inference as a fold. I actually don't mind this
code much as it is (about half or 2/3 the size it was an hour ago), but I'm
wondering if I can do better.

-- a sentence is a conjunction of clauses
type Sentence a = [Clause a]

-- each clause is a disjunction of terms
type Clause a = [Term a]

-- one sentence entails a second sentence if negating the second
-- and inserting its clauses, and the clauses that can be deduced, into
-- the first, results in a contradiction (which we'll represent as an
-- empty list of clauses)
entails :: Eq a = Sentence a - Sentence a - Bool
entails s1 s2 = null $ foldr (flip insertInto) s1 (neg s2)

insertInto :: Eq a = [Clause a] - Clause a - [Clause a]
insertInto [] _ = [] -- inserting into a contradictory set of clauses is
still contradictory
insertInto x y | contradiction y = [] -- inserting a clause which is
contradictory is also a contradiction
 | otherwise = foldr (flip insertInto) (y:x) (concatMap
(resolve y) x)

contradiction :: Clause a - Bool
contradiction = null

-- a list of all the ways the resolution law can be applied:
-- 
http://en.wikipedia.org/wiki/Resolution_(logic)#Resolution_in_propositional_logic
resolve :: Eq a = Clause a - Clause a - [Clause a]
resolve xs ys = [combine x (xs ++ ys) | x - xs, (neg_term x) `elem` ys]

combine :: Eq a = Term a - Clause a - Clause a
combine x = nub . delete x . delete (neg_term x)


On Sat, Jan 24, 2009 at 11:25 PM, Ryan Ingram ryani.s...@gmail.com wrote:

 My point is that without further knowledge of this function, it's not
 possible to simplify into a fold.  For f to be a fold, the result
 would have to terminate for *every* total function g; given that there
 are some total functions for which f does not terminate, f cannot be a
 fold.

 It's possible that the particular combination of f and g that you have
 in mind *does* simplify to a fold, but the current function cannot,
 unless I've made a mistake.

  -- ryan

 On Sat, Jan 24, 2009 at 7:26 PM, Andrew Wagner wagner.and...@gmail.com
 wrote:
  There's at least one thing; I won't call it a flaw in your logic, but
 it's
  not true of my usage. Your definition always produces a non-null list.
 The
  particular g in my mind will eventually produce a null list, somewhere
 down
  the line. I think if that's true, we can guarantee termination.
 
  On Sat, Jan 24, 2009 at 10:16 PM, Ryan Ingram ryani.s...@gmail.com
 wrote:
 
  foldr f z xs =
x0 `f` (x1 `f` (x2 `f` ... (xN `f` z) ...))
 
  In particular, note that if f is a total function, xs is finite and
  totally defined, and z is totally defined, then the result of this
  fold is totally defined.
 
  Now consider your f (rewritten slightly)
 
  f x xs
| null xs = []
| p x = []
| otherwise = foldr f (x:xs) (g x xs)
 
  with these definitions:
 
  c _ = False
  g = (:)
 
  c and g are definitely total functions, so what happens when we
  evaluate f 0 [1]?
 
  f 0 [1]
 = foldr f [0,1] [0,1]
 = let t1 = foldr f [0,1] [1] in f 0 $ t1
 = let t1 = foldr f [0,1] [1] in foldr f (0 : t1) (0 : t1)
 = let t1 = foldr f [0,1] [1]
   t2 = foldr f (0:t1) t1
   in f 0 t2
 
  etc.; this is clearly non-terminating.
 
  Therefore there is no way to make f into a fold.
 
  Any errors in my logic?
 
   -- ryan
 
  2009/1/24 Andrew Wagner wagner.and...@gmail.com:
   Ahem. That's what happens when you don't type-check your brainstorming
   before barfing it out, kids. Sorry about that. Let's try this again:
  
   f _ [] = []
   f y x | c y = []
   | otherwise = foldr f (y:x) (g y x)
  
   I've got a fold on the inside now, but I'm pretty sure the whole thing
   is
   just a fold. Not quite there yet, though...
  
   On Sat, Jan 24, 2009 at 1:42 PM, Andrew Wagner 
 wagner.and...@gmail.com
   wrote:
  
   Actually, I think I can rewrite it this way:
  
   f xs [] = False
   f xs (y:ys) | any c ys' = True
   | otherwise = f (f (y:xs) ys') ys
 where ys' = g y ys
  
   This should help, I think.
  
   On Sat, Jan 24, 2009 at 12:11 PM, Dan Doel dan.d...@gmail.com
 wrote:
  
   On Saturday 24 January 2009 11:39:13 am Andrew Wagner wrote:
This is almost a fold, but seemingly not quite? I know I've seem
some
talk
of folds that potentially quit early. but not sure where I saw
that,
or
if it fits.
   
f xs [] = False
f xs (y:ys) | any c ys' = True
   
| otherwise = f (nub (y:xs)) (ys' ++ ys)
   
   where ys' = g y xs
  
   Quitting early isn't the problem. For instance, any is defined in
   terms
   of
   foldr, and it works fine on infinite lists, quitting as soon as it
   finds
   a
   True. As long as you don't use the result of the recursive call
 (which
   is
   the
   second argument in the function you pass to foldr), it will exit
   early.
  
   The problem is that your function doesn't

Re: [Haskell-cafe] Why monoids will abide...

2009-01-22 Thread Andrew Wagner
See, that's the kind of name we need!
StructureWithAssociativeOperationAndIdentity -- make both the mathematicians
AND the non-mathematicians mad!

On Thu, Jan 22, 2009 at 9:53 AM, Dan Piponi dpip...@gmail.com wrote:

 On Wed, Jan 21, 2009 at 11:12 PM, Eugene Kirpichov ekirpic...@gmail.com
 wrote:
  To my mind, in the map-reduce case you generally need a commutative
  monoid. Or, you need an extra infrastructure that mappend's only
  results from adjacent machines, or something like that.

 This is a good paper on the stuff I'm talking about:
 http://citeseer.ist.psu.edu/blelloch90prefix.html It doesn't
 explicitly mention monoids but it's all about associative operations
 with identity.
 --
 Dan
 ___
 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] Haskell mode for Emacs question

2009-01-22 Thread Andrew Wagner
Interesting. I have a similar, but worse problem. For me, ':load'ing main.hs
would fail to find the imported files. The only thing I appear to be able to
:load is files that don't import from local directories.

2009/1/22 Peter Verswyvelen bugf...@gmail.com

 I have a silly problem.
 I'm using Emacs with the Haskell mode extension on Windows

 I have a source file in say

 c:/foo/src/main.hs

 main.hs is importing some other modules in that same src directory

 When I invoke GHCi from within Emacs, the first thing it does is

 :cd c:/foo

 and then

 :load src/main.hs

 But of course GHCi won't find the imported modules now, since the current
 directory is wrong.

 If I type in GHCi

 :cd src
 :load main.hs

 then it compiles fine.

 Does anyone have an idea why Emacs or the Haskell mode is switching to the
 parent directory of src instead of src itself, and how to fix this?

 Thanks a lot,
 Peter


 ___
 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] Haskell mode for Emacs question

2009-01-22 Thread Andrew Wagner
Hmm, strange. This doesn't appear to fix my problem. Perhaps I have
something bigger broken locally :(

On Thu, Jan 22, 2009 at 12:44 PM, Peter Verswyvelen bugf...@gmail.comwrote:

 indeed, that works! the comment above those lines is:
 ;; Not sure if it's useful/needed and if it actually works.

 :-)

 On Thu, Jan 22, 2009 at 6:41 PM, Miguel Mitrofanov 
 miguelim...@yandex.ruwrote:

 On my Mac I've had the same problem. Commenting out lines

  (unless (equal default-directory root)
(setq default-directory root)
(inferior-haskell-send-command
 proc (concat :cd  default-directory)))

 solved it for me.



 On 22 Jan 2009, at 20:23, Andrew Wagner wrote:

  Interesting. I have a similar, but worse problem. For me, ':load'ing
 main.hs would fail to find the imported files. The only thing I appear to be
 able to :load is files that don't import from local directories.

 2009/1/22 Peter Verswyvelen bugf...@gmail.com
 I have a silly problem.

 I'm using Emacs with the Haskell mode extension on Windows

 I have a source file in say

 c:/foo/src/main.hs

 main.hs is importing some other modules in that same src directory

 When I invoke GHCi from within Emacs, the first thing it does is

 :cd c:/foo

 and then

 :load src/main.hs

 But of course GHCi won't find the imported modules now, since the current
 directory is wrong.

 If I type in GHCi

 :cd src
 :load main.hs

 then it compiles fine.

 Does anyone have an idea why Emacs or the Haskell mode is switching to
 the parent directory of src instead of src itself, and how to fix this?

 Thanks a lot,
 Peter


 ___
 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] Employment

2009-01-22 Thread Andrew Wagner
That's..evil

On Thu, Jan 22, 2009 at 7:56 PM, Jonathan Cast jonathancc...@fastmail.fmwrote:

 On Tue, 2009-01-20 at 21:01 +, Andrew Coppin wrote:
  Paul Johnson wrote:
   So next time I hear the you can't get the programmers line I'm going
   to respond with something like this:
  
  If you post an advert for a Haskell developer you will get 20
  applicants.  All of those people will be the kind of developer who
  learns new programming languages to improve their own abilities and
  stretch themselves, because nobody yet learns Haskell just to get a
   job.
  
  If you post an advert for a Java developer you will get 200
  applicants.  Most of them will be the kind of developer who learned
  Java because there are lots of Java jobs out there, and as long as
  they know enough to hold down a job then they see no reason to learn
  anything.
 
  If this isn't an elevator pitch for using Haskell then I don't know
  what the hell *is*!
 
  Seriously, this is a pretty damned persuasive argument...

 Not really.  My company *advertises* for Haskell developers, and then
 when they come in to interview, informs them that the code base is
 actually written in Perl.  Works, too --- we have several Haskellers
 working here.  If all you care about is the quality of the developers,
 and not their productivity once you've got them, you don't actually need
 to let them use Haskell after the interview is over...

 jcc


 ___
 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] Quite confused by simple transformations on this code not working

2009-01-20 Thread Andrew Wagner
Strange little bit of code:
http://moonpatio.com:8080/fastcgi/hpaste.fcgi/view?id=829#a829

If I do any of the following, all of which seem natural to me, it fails to
typecheck:

   1. move f out of the 'where' clause (with or without a type signature)
   2. put the same type signature on f as is on (/\)
   3. replace f with (/\) completely

What's going on here?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Quite confused by simple transformations on this code not working

2009-01-20 Thread Andrew Wagner
So...there's just no good way to avoid the duplication?

On Tue, Jan 20, 2009 at 11:10 PM, wren ng thornton w...@freegeek.orgwrote:

 Andrew Wagner wrote:

 Strange little bit of code:
 http://moonpatio.com:8080/fastcgi/hpaste.fcgi/view?id=829#a829

 If I do any of the following, all of which seem natural to me, it fails to
 typecheck:

   1. move f out of the 'where' clause (with or without a type signature)
   2. put the same type signature on f as is on (/\)
   3. replace f with (/\) completely

 What's going on here?


 :t (nub .) . (++)
(nub .) . (++) :: (Eq a) = [a] - [a] - [a]

 :t foldr (map . (nub .) . (++))
foldr (map . (nub .) . (++)) :: (Eq a) = [[a]] - [[a]] - [[a]]

 The type you give to (/\) is more restrictive than the type of the
 expression, and f uses the generality of the expression.

 --
 Live well,
 ~wren
 ___
 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] Employment

2009-01-19 Thread Andrew Wagner
http://www.haskell.org/haskellwiki/Haskell_in_industry could be of interest
to you

On Mon, Jan 19, 2009 at 2:34 PM, Andrew Coppin
andrewcop...@btinternet.comwrote:

 Is it possible to earn money using Haskell? Does anybody here actually do
 this?

 Inquiring minds want to know... ;-)

 ___
 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] Employment

2009-01-19 Thread Andrew Wagner
 Such a database would help me counter by boss's
 argument that it's impossible to find and hire Haskell programmers.


Err, people actually say such things? And they say _we're_ out of touch with
the real world?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Simplification of this function?

2009-01-16 Thread Andrew Wagner
I've been playing around with this, but haven't been able to come up with
anything.
myFunc f (a,b) (c,d) = (f a c, f b d)

It feels as if there should be a nice simple version of this using some
combination of {un,}curry, on, , ***, or something else.

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


Re: [Haskell-cafe] Comments from OCaml Hacker Brian Hurt

2009-01-15 Thread Andrew Wagner
I think perhaps the correct question here is not how many instances of
Monoid are there?, but how many functions are written that can use an
arbitrary Monoid. E.g., the fact that there are a lot of instances of Monad
doesn't make it useful. There are a lot of instances of Monad because it's
useful to have instances of Monad. Why? Because of
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html !
Look at all the cool stuff you can automagically do with your type just
because it's an instance of Monad! I think that's the point. What can you do
with arbitrary Monoids? Not much, as evidenced by
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Monoid.html
On Thu, Jan 15, 2009 at 3:51 PM, Don Stewart d...@galois.com wrote:

 duncan.coutts:
  On Thu, 2009-01-15 at 19:46 +, Andrew Coppin wrote:
 
   PS. As a small aside... Is the Monoid class actually used *anywhere* in
   all of Haskell?
 
  Yes.
 
  They're used quite a lot in Cabal. Package databases are monoids.
  Configuration files are monoids. Command line flags and sets of command
  line flags are monoids. Package build information is a monoid.
 
  It is also used in the Foldable class which is a nice interface for
  traversing/visiting structures. Binary serialisation is also a monoid.

 Also, xmonad configuration hooks are monoidal. So all those xmonad users
 gluing together keybindings are using the Monoid class.

 -- Don
 ___
 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] Propositional logic implementation

2009-01-10 Thread Andrew Wagner
All,
Is there some better way to do this? It seems like a lot of boilerplate.
Thanks!

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


Re: [Haskell-cafe] Propositional logic implementation

2009-01-10 Thread Andrew Wagner
Nice Idea, though I don't know that I want something that extensive. I was
more looking for whether there was a better way I could define the algebraic
data type.

On Sat, Jan 10, 2009 at 6:04 PM, Miguel Mitrofanov miguelim...@yandex.ruwrote:

 Look at SYB (Data.Data, Data.Generics.*). For example, your symbols
 function can be rewritten as

 symbols :: Sentence - [Symbol]
 symbols s = nub $ listify (const True) s

 true is not that simple, because this code is NOT boilerplate - each
 alternative is valuable by itself.


 On 10 Jan 2009, at 23:56, Andrew Wagner wrote:

  All,
 Is there some better way to do this? It seems like a lot of boilerplate.
 Thanks!

 http://hpaste.org/13807#a1
 ___
 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: Monads aren't evil

2009-01-10 Thread Andrew Wagner
Holy concatenated operators, Batman!

Is that an operator or Batman?
 (yes, I know, 3 operators)

 --
 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



 ___
 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] Reading group for Programming Collective Intelligence

2008-12-30 Thread Andrew Wagner
I think this sounds like a great idea! I'll have to get ahold of the book
first though.

On Tue, Dec 30, 2008 at 8:10 PM, Creighton Hogg wch...@gmail.com wrote:

 Hello Haskellers,

 For those of your who aren't nose-deep in Real World Haskell at the
 moment, I'd like to start a small group for the O'Reilly book
 Programming Collective Intelligence*.  I think it might be very
 instructive to convert the examples  exercises to Haskell.  I think
 it would be good experience for doing neat applications in Haskell 
 may provide opportunities for adding to Hackage if the book relies on
 Python libraries that we don't have an equivalent for.

 If anyone is interested, just e-mail me  I can work on the organization.

 Cheers,
 Creighton

 * http://tinyurl.com/7x4rga
 ___
 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] instance Enum [Char] where ...

2008-12-29 Thread Andrew Wagner
Err, is this just for academic purposes, or is there some deeper reason you
want an Enum instance of String? That will dictate how to define the
functions. For example, you could just as easily imagine other definitions
of fromEnum, such as:

fromEnum = read . concatMap (show . ord)

Why? *shrug*...the types match. So...you need to figure out why you're doing
what you're doing before you can really figure out what you're doing.

Hope this helps!


On Mon, Dec 29, 2008 at 10:25 PM, JustinGoguen adek...@hamiltonshells.cawrote:

 I am having difficulty making [Char] an instance of Enum. fromEnum is easy
 enough: map fromEnum to each char in the string and take the sum. However,
 toEnum has no way of knowing what the original string was.

 For example, running fromEnum on the string d will result in 100. But
 when we
 pass 100 to toEnum, it does not know if it should treat 100 as d or 22
 (fromEnum '2' == 50).

 Source so far:

 instance Enum [Char] where
succ = undefined
pred = undefined
toEnum n = undefined -- what to do?
fromEnum xs = sum $ map fromEnum xs

 ___
 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] Typeclass question

2008-12-27 Thread Andrew Wagner
I'm sure there's a way to do this, but it's escaping me at present. I  
want to do something like this:


data Foo = Bar a = Foo a Bool ...

That is, I want to create a new type, Foo, whose constructor takes  
both a Boolean and a value of a type of class Bar.

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


Re: [Haskell-cafe] Typeclass question

2008-12-27 Thread Andrew Wagner

Hmm, I actually simplified my problem too much. What I actually want is:
data Foo a = forall a. Bar a = Foo a Bool

...except I want the 'a' on the left to match the 'a' on the right, so  
that you can only construct values out of values of the parameterized  
type, which also must be of the Bar class.


On Dec 27, 2008, at 1:44 PM, David Menendez d...@zednenem.com wrote:

On Sat, Dec 27, 2008 at 2:24 PM, Andrew Wagner wagner.and...@gmail.com 
 wrote:
I'm sure there's a way to do this, but it's escaping me at present.  
I want

to do something like this:

data Foo = Bar a = Foo a Bool ...

That is, I want to create a new type, Foo, whose constructor takes  
both a

Boolean and a value of a type of class Bar.


Try this:

   {-# LANGUAGE ExistentialQuantification #-}

   data Foo = forall a. Bar a = Foo a Bool


--
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] Monades - I've got it! (hopefully)

2008-12-24 Thread Andrew Wagner
I wouldn't call it a programming model so much as a library. A
programming model sounds to me like an idiom, whereas there's an actual
typeclass in the standard library called Monad. Yes, there's special sugar
built into GHC (and, likely, any haskell implementation) for it, but it
really is at its heart just a typeclass.

On Wed, Dec 24, 2008 at 5:28 AM, Tobias Kräntzer
i...@tobias-kraentzer.dewrote:

 Am 24.12.2008 um 11:56 schrieb Luke Palmer:

 It is only a concept of the language insofar as it is needed to do IO
 (because of the IO monad).  You are correct that it is really more of a
 programming model.
 [...]
 About the prestress, that's one of the motivations behind renaming them
 (warm fuzzy thing is the current tongue-in-cheek alternative).


 I think it would help a lot, if this would be mentioned in all the
 explanations. Maybe I over read it, but the information that monads are a
 data structure, which are used to do for example IO and no special
 datatypes would help.

 But enough programming for these days.

 . . . Tobias

 --
 Tobias Kräntzer
 i...@tobias-kraentzer.de



 ___
 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] Defining a containing function on polymorphic list

2008-12-22 Thread Andrew Wagner
The problem here is even slightly deeper than you might realize. For
example, what if you have a list of functions. How do you compare two
functions to each other to see if they're equal? There is no good way really
to do it! So, not only is == not completely polymorphic, but it CAN'T be.

There is a nice solution for this, however, and it's very simple:

contain :: Eq a - [a] - Bool
contain x [] = False
contain x (y:ys) = if x == y then True else contain x ys

The Eq a in the type signature says that 'a' must be a member of the 'Eq'
typeclass. That says, in turn, that 'a' must have == defined for it.
Fortunately, most types have, or can easily derive that definition. Here is
the definition of the typeclass:

class 
Eqhttp://haskell.org/ghc/docs/latest/html/libraries/base/Data-Eq.html#t%3AEqa
where(==)http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Eq.html#v%3A%3D%3D::
a - a -
Boolhttp://haskell.org/ghc/docs/latest/html/libraries/ghc-prim/GHC-Bool.html#t%3ABool
(/=)http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Eq.html#v%3A%2F%3D::
a - a -
Boolhttp://haskell.org/ghc/docs/latest/html/libraries/ghc-prim/GHC-Bool.html#t%3ABool
That is, for 'a' to be a member of 'Eq', it must have a == operator which
can take 2 values of that type and return a Boolean, saying whether or not
they're equal, and it must also have a definition for the /= operator, which
is not equal. These two are also defined in terms of each other, so if you
define ==, you get /= for free, and vice versa.

That's probably more information than you needed to know, but I hope it
helps.

2008/12/22 Raeck Zhao ra...@msn.com

  I am trying to define a containing function to see if a value is one of
 the elements within a list which is polymorphic, but failed with the
 following codes:
  contain :: a - [a] - Bool
  contain x [] = False
  contain x (y:ys) = if x == y then True else contain x ys it seems that
 the problem is the 'operator' == does not support a polymorphic check?
 Any way can solve the problem? or any alternative solution to achieve the
 purpose?
 Thanks!
 Raeck

 --
 It's the same Hotmail(R). If by same you mean up to 70% faster. Get your
 account 
 now.http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_broad1_122008

 ___
 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] Defining a containing function on polymorphic list

2008-12-22 Thread Andrew Wagner
Yes, of course, sorry for the typo.

On Mon, Dec 22, 2008 at 9:17 AM, Denis Bueno dbu...@gmail.com wrote:

 2008/12/22 Andrew Wagner wagner.and...@gmail.com:
  The problem here is even slightly deeper than you might realize. For
  example, what if you have a list of functions. How do you compare two
  functions to each other to see if they're equal? There is no good way
 really
  to do it! So, not only is == not completely polymorphic, but it CAN'T be.
 
  There is a nice solution for this, however, and it's very simple:
 
  contain :: Eq a - [a] - Bool

 Please note that the syntax here should be:

contain :: Eq a = a - [a] - Bool

  Denis

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


Re: [Haskell-cafe] Defining a containing function on polymorphic list

2008-12-22 Thread Andrew Wagner
There are two ways to fix this. Let me see if I can get my syntax right this
time :)

1.) Let GHC work out the Eq instance:
  data Shape = Square | Triangle | Circle deriving Eq

2.) Tell GHC how to do it explicitly:
  data Shape = Square | Triangle | Circle
  instance Eq Shape where
Square == Square = True
Triangle == Triangle = True
Circle == Circle = True
_ == _ = False

Note that the last line here means that any other comparisons are false.

On Mon, Dec 22, 2008 at 9:35 AM, Raeck Zhao ra...@msn.com wrote:

  Thank you very much for your reply! It is really helpful!

 But I just found another 'problem', I just realize that the list does not
 support the user-defined data type?
 the list is also depending on the Eq function?

 For example,

 data Shape = Square | Triangle | Circle

 when I type either

 [Square, Triangle, Circle]

 or

 Square == Square

 there are errors!

 So there is no way to construct a truly polymorphic List? any way to extend
 the list to support some user-defined data type?

 Or...  I define the Shape in a wrong way actually?

 Thanks

 Raeck


 --
 Date: Mon, 22 Dec 2008 09:02:53 -0500
 From: wagner.and...@gmail.com
 To: ra...@msn.com
 Subject: Re: [Haskell-cafe] Defining a containing function on polymorphic
 list
 CC: haskell-cafe@haskell.org; beginn...@haskell.org

 The problem here is even slightly deeper than you might realize. For
 example, what if you have a list of functions. How do you compare two
 functions to each other to see if they're equal? There is no good way really
 to do it! So, not only is == not completely polymorphic, but it CAN'T be.

 There is a nice solution for this, however, and it's very simple:

 contain :: Eq a - [a] - Bool
 contain x [] = False
 contain x (y:ys) = if x == y then True else contain x ys

 The Eq a in the type signature says that 'a' must be a member of the 'Eq'
 typeclass. That says, in turn, that 'a' must have == defined for it.
 Fortunately, most types have, or can easily derive that definition. Here is
 the definition of the typeclass:

 class 
 Eqhttp://haskell.org/ghc/docs/latest/html/libraries/base/Data-Eq.html#t:Eqa
 where 
 (==)http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Eq.html#v:%3D%3D::
  a - a -
 Boolhttp://haskell.org/ghc/docs/latest/html/libraries/ghc-prim/GHC-Bool.html#t:Bool
 (/=)http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Eq.html#v:/%3D::
  a - a -
 Boolhttp://haskell.org/ghc/docs/latest/html/libraries/ghc-prim/GHC-Bool.html#t:Bool
 That is, for 'a' to be a member of 'Eq', it must have a == operator which
 can take 2 values of that type and return a Boolean, saying whether or not
 they're equal, and it must also have a definition for the /= operator, which
 is not equal. These two are also defined in terms of each other, so if you
 define ==, you get /= for free, and vice versa.

 That's probably more information than you needed to know, but I hope it
 helps.

 2008/12/22 Raeck Zhao ra...@msn.com

  I am trying to define a containing function to see if a value is one of
 the elements within a list which is polymorphic, but failed with the
 following codes:
  contain :: a - [a] - Bool
  contain x [] = False
  contain x (y:ys) = if x == y then True else contain x ys it seems that
 the problem is the 'operator' == does not support a polymorphic check?
 Any way can solve the problem? or any alternative solution to achieve the
 purpose?
 Thanks!
 Raeck

 --
 It's the same Hotmail(R). If by same you mean up to 70% faster. Get your
 account 
 now.http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_broad1_122008

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



 --
 Life on your PC is safer, easier, and more enjoyable with Windows Vista(R). 
 See
 how http://clk.atdmt.com/MRT/go/127032870/direct/01/

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


Re: [Haskell-cafe] Pattern combinators

2008-12-21 Thread Andrew Wagner
I'd love to see a copy of this go up on hackage for experimentation. Would
you care to upload your code, or send it to me so I can upload it?

On Sun, Dec 21, 2008 at 12:37 AM, David Menendez d...@zednenem.com wrote:

 On Sat, Dec 20, 2008 at 9:34 PM, Jacques Carette care...@mcmaster.ca
 wrote:
  Andrew Wagner wrote:
 
  Wadler posted a blog entry the other day about a paper on
 pattern-matching
  in Haskell (http://wadler.blogspot.com/). I've taken a first stab at
 turning
  it into actual code for hackage (http://hpaste.org/13215). There are
 two
  commented-out definitions that don't type-check, though, and the types
 are
  too wild for me to grok. Anybody have any suggestions for 1.) How to fix
 it
  and/or 2.) How to use data/type/newtype to simplify the types and make
 it
  more manageable? Thanks!
 
  Both errors are because you are using any instead of any'; you might
  wish to put
  import Prelude hiding any
  at the top of your code, just to avoid such confusion.

 Example 14 also uses (.-.) where it should use (..), and it either
 needs some more parentheses or some precedence declarations for the
 operators.

  To make the types more readable (but not necessarily more manageable), I
  have made some changes to my version of this code.

 One oddity in the paper is the type of the failure continuations, ()
 - ans. I'm guessing that's left over from an earlier phase of
 development. In my own transcription of the library, I eliminated the
 () parameter without apparent loss of functionality.

 I think I've managed to work out the structure of the types, which can
 mostly be expressed in modern Haskell.

 The matching part of the patterns have this general form:

type PMatch vec vec' ans = (vec - ans) - (() - ans) - vec' - ans

 where vec and vec' are the list of argument types before and after the
 subpattern match, and ans is the final answer. (In my code, I just use
 ans instead of () - ans for the failure continuation.)

 This gets us:

 nil   :: PMatch vec vec ans
 one   :: a - PMatch (a,vec) vec ans
 (#)   :: PMatch vec vec' ans - PMatch vec' vec'' ans - PMatch vec vec''
 ans
 fail  :: PMatch vec vec' ans
 catch :: PMatch vec vec' ans - PMatch vec vec' ans - PMatch vec vec' ans

 These types are less general than the ones Haskell would infer, but
 they do not appear to lose any functionality.

 The currying part of the pattern is less easy to analyze. I've been
 able to use type families to relate the curried and uncurried form of
 the function types, but I'm working with GHC 6.8, so it's possible
 this won't work with the more modern implementations.

 Given the list of argument types and the answer type, generate a
 curried function type:

type family Curry vec ans
type instance Curry () ans = ans
type instance Curry (a,vec) ans = a - Curry vec ans

 zero, succ zero, and so forth take a function in curried form and
 transform it into a function that takes a nested tuple:

type CurryDigit vec ans = Curry vec ans - vec - ans

zero :: CurryDigit () ans
succ zero :: CurryDigit (a,()) ans

succ :: CurryDigit vec ans - CurryDigit (a,vec) ans
succ . succ :: CurryDigit vec ans - CurryDigit (a,(b,vec)) ans

 So the currying part of the pattern will have the form:

type PCurry vec vec' ans = CurryDigit vec' ans - CurryDigit vec ans

 So a pattern has the type,

type Pattern a vec vec' ans = (PCurry vec vec' ans, a - PMatch
 vec vec' ans)

 where a is the value being examined, vec and vec' are the list of
 unbound argument types before and after the match, and ans is the
 result.

var :: Pattern a (a,vec) vec ans
cst :: (Eq a) = a - Pattern a vec vec ans
pair :: Pattern a vec vec' ans - Pattern b vec' vec'' ans -
 Pattern (a,b) vec vec'' ans


 Coming from the other side, match takes a value and a case statement
 and produces a result:

type Case a ans = a - (() - ans) - ans   -- or just a - ans -
 ans in my code

match :: a - Case a ans - ans

 (|||) combines case statements:

(|||) :: Case a ans - Case a ans - Case a ans

 and (-) creates them from a pattern and a curried function,

(-) :: Pattern a vec () ans - Curry vec ans - Case a ans

 Note that (-) requires the pattern to leave no unbound variables
 after matching.


 Given the way everything is polymorphic in ans, it may be possible to
 hide it, but I haven't tried yet.


  The principal weakness of these pattern-matching combinators is that
 there
  is no support for algebraic types, i.e. things like
  data Tree a = Leaf | Branch (Tree a) (Tree a)
  I can see how to use Typeable to deal with that, but is there a simpler
 way?

 You can define the patterns manually:

 leaf = (id, \v - case v of { Leaf - nil; _ - fail })

 branch p q = (curry_p . curry_q, \v - case v of { Branch l r -
 match_p l # match_q r; _ - fail})
where
(curry_p, match_p) = p
(curry_q, match_q) = q

 I assume generating these would be pretty straightforward to automate
 with Template

[Haskell-cafe] Pattern combinators

2008-12-20 Thread Andrew Wagner
All,
Wadler posted a blog entry the other day about a paper on pattern-matching
in Haskell (http://wadler.blogspot.com/). I've taken a first stab at turning
it into actual code for hackage (http://hpaste.org/13215). There are two
commented-out definitions that don't type-check, though, and the types are
too wild for me to grok. Anybody have any suggestions for 1.) How to fix it
and/or 2.) How to use data/type/newtype to simplify the types and make it
more manageable? Thanks!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Functional version of this OO snippet

2008-12-05 Thread Andrew Wagner

Hi all,
public interface IEngine {
  void foo();
  void bar(string bah);
  ...
}
public class Program {
 public void Run(IEngine engine){
  while(true){
string command = GetLine();
if (command.startsWith(foo)){
  engine.foo();
} else if (command.startsWith(bar)){
  engine.bar(command);
...
else break;
}

In other words, I want to provide the same UI across multiple  
implementations of the engine that actually processes the commands.


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


[Haskell-cafe] Re: Binary Trees missing on hackage

2008-12-01 Thread Andrew Wagner
The reasons I've always heard for this is that 1.) It's so easy to define a
tree and 2.) There are tons of different variations of trees and what you
can do with them. Not that I 100% agree, just what I've always heard.

On Mon, Dec 1, 2008 at 6:09 AM, Christian Maeder
[EMAIL PROTECTED]wrote:

 Hi,

 I was surprised that I could not find a classical binary tree data
 structure on hackage, mainly for teaching purposes, like:

  data BinTree a = Nil | Node (BinTree a) a (BinTree a)

 with a couple of utility functions and instances (i.e. in-order traversal).

 Surely, one may argue, that such a tree can always be defined on the fly
 when needed, but nobody would argue so for lists or tuples. (Although
 I've rarely seen someone redefining lists, it is quite common to
 introduce user-defined products or enumerations.)

 There are rose trees in Data.Tree and many other variants of trees are
 conceivable, ie.

  data Boom a = Leaf a | Node (Boom a) (Boom a)

 or a kind of combination:

  data BinLeafTree a b =
 Leaf b
   | Node (BinLeafTree a b) a (BinLeafTree a b)

 I don't know, why I find the above BinTree most important. I'm not even
 sure if such a tree could be re-used for Search- or AVL-trees that need
 strict fields with redundant size or height counters for efficiency
 reasons.

 In any case I would find such a data type at least as useful as
 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/OneTuple

 Who would supply and maintain such a package? Or did I simply not search
 hard enough?

 Cheers Christian

 P.S. I took the (non-empty) Boom from the Boom-Hierarchy described in
 An Exploration of the Bird-Meertens Formalism by Roland Backhouse
 1988, Groningen

 ___
 Libraries mailing list
 [EMAIL PROTECTED]
 http://www.haskell.org/mailman/listinfo/libraries

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


[Haskell-cafe] Re: Binary Trees missing on hackage

2008-12-01 Thread Andrew Wagner
Hm, I've been thinking about this this morning as I've gone about my
commute. I could indeed imagine a class like the following that had multiple
implementations like you're talking about:
class Tree t where
  drawTree :: t String - String
  flatten :: t a - [a]
  etc. (see
http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Tree.html)http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Tree.html

I think that for this to be valuable, though, we would need to show that
there are functions which can take a generic Tree t and do something useful
with it. Still, I suspect there's something there. Maybe I'll take a stab at
it this week sometime.

On Mon, Dec 1, 2008 at 6:24 AM, Andrew Wagner [EMAIL PROTECTED]wrote:

 The reasons I've always heard for this is that 1.) It's so easy to define a
 tree and 2.) There are tons of different variations of trees and what you
 can do with them. Not that I 100% agree, just what I've always heard.

 On Mon, Dec 1, 2008 at 6:09 AM, Christian Maeder [EMAIL PROTECTED]
  wrote:

 Hi,

 I was surprised that I could not find a classical binary tree data
 structure on hackage, mainly for teaching purposes, like:

  data BinTree a = Nil | Node (BinTree a) a (BinTree a)

 with a couple of utility functions and instances (i.e. in-order
 traversal).

 Surely, one may argue, that such a tree can always be defined on the fly
 when needed, but nobody would argue so for lists or tuples. (Although
 I've rarely seen someone redefining lists, it is quite common to
 introduce user-defined products or enumerations.)

 There are rose trees in Data.Tree and many other variants of trees are
 conceivable, ie.

  data Boom a = Leaf a | Node (Boom a) (Boom a)

 or a kind of combination:

  data BinLeafTree a b =
 Leaf b
   | Node (BinLeafTree a b) a (BinLeafTree a b)

 I don't know, why I find the above BinTree most important. I'm not even
 sure if such a tree could be re-used for Search- or AVL-trees that need
 strict fields with redundant size or height counters for efficiency
 reasons.

 In any case I would find such a data type at least as useful as
 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/OneTuple

 Who would supply and maintain such a package? Or did I simply not search
 hard enough?

 Cheers Christian

 P.S. I took the (non-empty) Boom from the Boom-Hierarchy described in
 An Exploration of the Bird-Meertens Formalism by Roland Backhouse
 1988, Groningen

 ___
 Libraries mailing list
 [EMAIL PROTECTED]
 http://www.haskell.org/mailman/listinfo/libraries



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


Re: [Haskell-cafe] (A little humour)

2008-09-26 Thread Andrew Wagner
Brilliant. This made my day. I must admit, I looked briefly at the
paper after I saw the link, yawned, and closed it. Then I saw Andrew's
comment, skimmed the paper, becoming more and more convinced that it
was a joke, saw the last line, and then had to go back and read the
whole thing again. Just awesome.

On Fri, Sep 26, 2008 at 3:22 PM, Andrew Coppin
[EMAIL PROTECTED] wrote:
 Miguel Mitrofanov wrote:

 I think you might be interested in
 http://www.research.att.com/~bs/whitespace98.pdf

 Thankyou. That is the most insane thing I've read all day. And I've been
 reading a C++ tutorial all day! o_O

 ___
 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] Trees (Rose Trees?)

2008-07-21 Thread Andrew Wagner
There are a few different kinds of trees, but if you only need to
store data on the leaves, that representation will work. As for your
sumTree function, you are indeed missing a case...consider sumTree
(Leaf 3)! Once you deal with that case, the other two can actually be
combined (since sum [] = 0).

2008/7/21 Ryan Bloor [EMAIL PROTECTED]:
 hi

 I was curious as to whether my implementation of a Rose Tree and a sumTree
 function was correct. The aumTree adds up the elements of a tree.

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

 sumTree :: Tree Int - Int
 sumTree (Node []) = 0
 sumTree (Node xs) = sum (map sumTree xs)

 The problem with this is I get a pattern matching error. Am I representing
 trees right... see below.

 Also, would an empty tree be represented by ... Node [] with this
 implementation?
 How would I represent a tree of the form... Tree (Node 2(Node 6 Empty Empty)
 Empty) taken from a binary one.
 Like this? Node [ [Leaf 2], Node [ Leaf 6,Node[],Node[] ], Node[] ]

 Ryan



 
 Find out how to make Messenger your very own TV! Try it Now!
 ___
 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] Having trouble with zip12..

2008-07-06 Thread Andrew Wagner
Wow. Where did you come up with the stack trace? That's...impressive.

On Sun, Jul 6, 2008 at 5:07 PM, Don Stewart [EMAIL PROTECTED] wrote:
 I win, almost ...

13:13:18 dons dolio: yeah, it was ... almost ... an April 1 style post

 :)

 And yes, this was truly shocking on a number of levels. However, we have
 people doing a lot of weird things with Haskell these days, so its not
 as absurd that someone would be hacking up a zip12 for an air traffic
 control system on some MS platform, with SQL in the backend, as it might
 have been a few years ago :)

 mfeathers:

 Sorry guys.  I was just bored on a Sunday afternoon so I thought I'd
 type up a little joke.  I thought to myself Gee, how outrageous can I
 make it?

 1) Using and debugging a zip12 function.
 2) That fails only on 'take 5' (Brubeck fans take note)
 3) Has some absurd arguments like (nub . nub)
 4) Is embedded in an air traffic control system
 5) Is written in a Microsoft variant of Haskell called H#
 6) Silently makes SQL calls when evaluating a pure function
 7) Yields an mile long stack trace

 Sorry all.  Boredom made me do it,

 Michael

 Paul Visschers wrote:
 You're zipping 12 lists here, so how about testing each list
 individually? This will narrow down the problem considerably.
 
 Michael Feathers wrote:
 
 I have some code that looks like this and I'm having trouble with it:
 
 
 zip12 ((tails . nub) flightPaths) wayPoints etopsPackets (hd geoCaches)
   groundSpeeds headings (map windShift headings) (regulations !! 2)
   (foldr (\|/) (tail pathDistances)) [ghy x | x - [1..], full x]
   (nub . nub) arrivalSchedule
 
 
 The domain is air traffic control and I need to generate 12-tuples for
 aircraft that are within a particular radius of the tower.
 
 When I evaluate that expression with 'take 4' it works fine.  When I
 evaluate it with 'take 6' it works as well.  But, when I evaluate it
 with 'take 5' I get the following runtime error from H# in Visual Studio
 (it runs fine on the command line).  This is particularly odd because
 I'm not using Sql.
 
 
 
 The type initializer for 'System.Data.SqlClient.SqlConnection' threw an
 exception.
 Exception (TypeInitializationException): Source=System.Data;
 Target=null; Tag=null; TypeName=System.Data.SqlClient.SqlConnection;
 Message = The type initializer for
 'System.Data.SqlClient.SqlConnection' threw an exception.
 InnerException (TypeInitializationException): Source=System.Data;
 Target=null; Tag=null;
 Message = The type initializer for
 'System.Data.SqlClient.SqlConnectionFactory' threw an exception.
 StackTrace =  at System.Data.SqlClient.SqlConnection..cctor()
 InnerException (TypeInitializationException): Source=System.Data;
 Target=null; Tag=null;
 Message = The type initializer for
 'System.Data.SqlClient.SqlPerformanceCounters' threw an exception.
 StackTrace =
  at System.Data.SqlClient.SqlConnectionFactory..ctor()
 at System.Data.SqlClient.SqlConnectionFactory..cctor()
 InnerException (ConfigurationErrorsException):
 Source=System.Configuration; Target=null; Tag=null; Line=21;
 Message =
 The value of the property 'traceOutputOptions' cannot be parsed. The
 error is: The enumeration value must be one of the following: None,
 LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId,
 Callstack. (C:\Documents and
 Settings\Paey\Desktop\Projects\RPMC\bin\Debug\RPMC.vshost.exe.config
 line 21)
 StackTrace =
  at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[]
 keys, SectionInput input, Boolean isTrusted, FactoryRecord
 factoryRecord, SectionRecord sectionRecord, Object parentResult)
 at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord
 factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean
 getLkg, Boolean getRuntimeObject, Object result, Object
 resultRuntimeObject)
 at
 System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
 configKey, Boolean getLkg, Boolean checkPermission, Boolean
 getRuntimeObject, Boolean requestIsHere, Object result, Object
 resultRuntimeObject)
 at
 System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
 configKey, Boolean getLkg, Boolean checkPermission, Boolean
 getRuntimeObject, Boolean requestIsHere, Object result, Object
 resultRuntimeObject)
 at
 System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String
 configKey, Boolean getLkg, Boolean ch... (truncated) ...olean
 checkPermission)
 at System.Configuration.BaseConfigurationRecord.GetSection(String
 configKey)
 at
 System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String
 sectionName)
 at System.Configuration.ConfigurationManager.GetSection(String
 sectionName)
 at System.Configuration.PrivilegedConfigurationManager.GetSection(String
 sectionName)
 at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
 at System.Diagnostics.DiagnosticsConfiguration.Initialize()
 at 

Re: [Haskell] on starting Haskell-Edu, a new education-related Haskell-related mailing list

2008-07-02 Thread Andrew Wagner
I would certainly join such a list. My only concer would be that
moderating such a list could be tricky. How do you judge when a
discussion has become too technical? And what do you do about it?
Force the members to take it to -cafe? Anyway, I like the idea of
having a more beginner-friendly list, and have suggested something
similar for the IRC channel multiple times.


On Wed, Jul 2, 2008 at 3:39 AM, Benjamin L. Russell
[EMAIL PROTECTED] wrote:
 So far, I have received three positive responses on starting the new 
 Haskell-Edu mailing list, and no negative responses.

 In the latest response, the respondent suggested that I post another message 
 to this mailing list advising readers on how to react.  Basically, the 
 Haskell.org mailing list administrator, Simon Marlow, had originally 
 suggested that I ask for feedback on my idea from this mailing list, and wait 
 for the discussion to proceed to Haskell-Cafe, so for those interested in 
 this idea, please respond either in this thread or, after a few rounds, in 
 Haskell-Cafe on whether you agree, disagree, feel neutral, or have mixed 
 feelings regarding this idea.

 In any case, as the above-mentioned respondent suggested, rapid responses to 
 questions on the new mailing list will probably prove vital to keeping it 
 alive.  Participation by educators using Haskell, once Haskell-Edu is 
 started, would be most welcome.

 Please post your responses initially in this thread.  After a few rounds, 
 this discussion will probably move to Haskell-Cafe.

 -- Benjamin L. Russell

 --- On Tue, 7/1/08, Benjamin L. Russell [EMAIL PROTECTED] wrote:

 From: Benjamin L. Russell [EMAIL PROTECTED]
 Subject: [Haskell] on starting Haskell-Edu, a new education-related 
 Haskell-related mailing list
 To: The Haskell Mailing List haskell@haskell.org
 Date: Tuesday, July 1, 2008, 8:37 PM
 I am interested in starting a new mailing list on
 Haskell.org, aimed mainly at liberal arts teachers and
 elementary-level learners of Haskell, called
 Haskell-Edu: The Haskell Educational Mailing
 List.  This new mailing list would be guided by the
 principle that Haskell is useful not just in research, but
 also in teaching programming as part of a liberal arts
 education, on a par with Scheme.  When I suggested the idea
 of this mailing list to Simon Marlow, the Haskell.org
 mailing list administrator, he suggested that I post this
 idea on The Haskell Mailing List, so I am posting it here
 to ask for feedback.

 The main purposes of this new (proposed) mailing list would
 be as follows:

 1) To provide a primarily non-research-oriented discussion
 forum to serve the needs of users wishing to focus on the
 uses of Haskell in education, such as in high school and in
 introductory computer science college courses, as opposed to
 in research.

 2) To provide a primarily non-research-oriented discussion
 forum to serve the needs of non-computer-science students
 of Haskell who wish to focus on Haskell as a language for
 learning programming as part of a well-rounded a liberal
 arts education, as opposed to an
 engineering/mathematics/science-oriented education.

 Currently, there are two main Haskell mailing lists:

 a) The Haskell Mailing List, currently used mainly for
 announcements and for non-beginner discussions

 b) The Haskell-Cafe, currently ostensibly used for
 everything else, but in fact used primarily for serious
 academic computer-science research-oriented discussion of
 the language Haskell.

 Neither mailing list addresses Haskell as a tool for
 teaching functional programming as part of a liberal arts
 education, and while The Haskell Cafe is ostensibly
 responsible for addressing beginner questions, I have
 witnessed several instances in which new users who were not
 familiar with the academic culture of The Haskell Cafe have
 been frowned upon for either posting messages that did not
 assume enough mathematical background, or for posting
 messages that were written in a tongue-in-cheek style, and
 that therefore did not fit into the serious tone of the
 mailing list.

 (For example, a few months ago, one poster received a
 private e-mail message from another poster asking the
 former not to pollute The Haskell-Cafe Mailing
 List for assuming that screen pixel resolution was somehow
 related to the precision of an algorithm that picked points
 randomly from a square in approximating pi.  Avoiding this
 question required the knowledge that screen resolution
 could be considered independently from the precision of the
 algorithm itself, but while this point may be elementary to
 mathematicians and researchers, the poster was not familiar
 enough with the issue to grasp this immediately, and
 received the above-mentioned response.)

 This new mailing list is intended to cover both the issue
 of teaching Haskell as part of a liberal arts curriculum,
 and of answering beginner questions about Haskell from
 students who may not have a sophisticated mathematics
 background. 

Re: [Haskell-cafe] Haskell, Microsoft, and interview questions

2008-06-26 Thread Andrew Wagner
 Did they score you on coding or on geometry?


It was definitely more on coding and my ability to think about the problem.

 For what it's worth, a 3-dimensional kd tree really flew on this problem.


I did some reading up on this, and it seems interesting. It would be
need to implement something like this in Haskell, but I can't seem to
find any detailed specs on the data-structure. Got any
recommendations?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


  1   2   >