Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Circular programming (Peter Verswyvelen)
   2.  learning to use Haskell types (Michael Mossey)
   3.  Re: Closure (Daniel Bastos)
   4. Re:  Re: Closure (Daniel Fischer)
   5. Re:  Re: Closure (Brandon S. Allbery KF8NH)
   6.  Re: Closure (Daniel Bastos)
   7.  Re: Closure (Daniel Bastos)
   8. Re:  Re: Closure (Daniel Fischer)
   9.  List combination function? (Ian Duncan)


----------------------------------------------------------------------

Message: 1
Date: Sat, 15 Aug 2009 14:27:54 +0200
From: Peter Verswyvelen <bugf...@gmail.com>
Subject: Re: [Haskell-beginners] Circular programming
To: Maciej Piechotka <uzytkown...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <a88790d10908150527s2ef5f9bdw54f7d7c2dcfc...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

oh and reading first about fix should help too:
http://en.wikibooks.org/wiki/Haskell/Fix_and_recursion
<http://en.wikibooks.org/wiki/Haskell/Fix_and_recursion>

On Sat, Aug 15, 2009 at 1:43 PM, Peter Verswyvelen <bugf...@gmail.com>wrote:

> It might help to read the Yampa 
> Arcade<http://haskell.cs.yale.edu/yale/papers/haskell-workshop03/yampa-arcade.pdf>and
>  then Plugging
> a Space Leak with an 
> Arrow<http://cs-www.cs.yale.edu/homes/hl293/download/leak.pdf>to get a 
> practical example of circuit and circular programming.
>
> On Sat, Aug 15, 2009 at 11:16 AM, Maciej Piechotka 
> <uzytkown...@gmail.com>wrote:
>
>> I'm not understending circular programming. What it is used for?
>> Where feedback variable came from (yes - I know it's wrong question as
>> Haskell
>> is lazy)?
>>
>> I've read http://www.haskell.org/haskellwiki/Circular_programming but I
>> didn't
>> understend the concept and pattern.
>>
>> Regards
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090815/f922ad19/attachment-0001.html

------------------------------

Message: 2
Date: Sat, 15 Aug 2009 07:36:46 -0700
From: Michael Mossey <m...@alumni.caltech.edu>
Subject: [Haskell-beginners] learning to use Haskell types
To: beginners <beginners@haskell.org>
Message-ID: <4a86c7fe.2080...@alumni.caltech.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

This is really a general question, but any advice is welcome.

I'm currently working through Typeclassopedia and all the tutorials it 
links to. I'm really enjoying it, but a kind of scary question is: when I 
begin to write "real" software in Haskell, how will I find natural places 
to use the types and how will I make the transition to idiomatic Haskell?

[Note: the main application I have for Haskell is my music composition 
hobby. I plan to use Haskell to write software for editing music and for 
computer-assisted composition (CAC). CAC means the computer does some of 
the tedious work involved in searching for, and evaluation of, combinations 
of musical themes. All my algorithms are personal to my own process. There 
is no off-the-shelf software that can help me. That's why it's fortunate 
I'm a programmer. The CAC features need to be tightly integrated into a 
musical score editor, hence I have to write that too. Really quite a fun 
project, and even if it takes two years, I will get years and years of 
enjoyment from it!]

Then it occurred to me that a common theme in Haskell is to provide a way 
to express a solution to a problem in an expressive form that is natural to 
that problem. So maybe what I need to do is stop thinking, "Where can I use 
this type," and instead dream up ways to express ideas in a simple and 
natural form, then make use of Haskell types and type classes to make that 
expressive form a reality.

For example, in a music editor, there are many actions that create new 
notes. A note needs many pieces of information to describe it: the note's 
place in time, its duration, dynamics, whether tied to successive notes, 
type of flag or beam... Much of this information can be inferred from the 
context in which the note is created, and so a natural expressive language 
would bring a new note into existence with a minimal need for providing 
details. Those details would be inferred from the context. So that's a 
Reader monad right there.

Thanks,
Mike





------------------------------

Message: 3
Date: Sat, 15 Aug 2009 16:07:08 +0000 (UTC)
From: Daniel Bastos <dbasto...@toledo.com>
Subject: [Haskell-beginners] Re: Closure
To: beginners@haskell.org
Message-ID: <h66mfc$sc...@ger.gmane.org>

In article <h65p0h$rj...@ger.gmane.org>,
Heinrich Apfelmus wrote:

> The simplest example of a closure is indeed
>
>    foo = add 3
>
> where
>
>    add = \x y -> x + y

Question. This is actually equal to 

add x y = x + y

But you wrote in terms of \. Why such preference?

> Reduction to weak head normal form yields
>
>    foo = let x = 3 in \y -> x + y
>
> which means that  foo  is a function  \y -> x + y  paired with the value
> of the free variable  x .

I see.

> Note that closures are an implementation detail. From a semantic point
> of view,  add 3  can readily be understood as an ordinary function.

This makes sense. Because, even in a language like C, a similar effect
can be achieved, no? For example

int plus(int x, int y) { return x + y; }

int plus3(int y) { plus(3, y); }

So, what I can't do in C, besides almost everything I can't do, is to
do this nicely like I do in Haskell. But we don't call this a
closure. In fact, we say C does not allow for closures. So what am I
missing?



------------------------------

Message: 4
Date: Sat, 15 Aug 2009 18:31:14 +0200
From: Daniel Fischer <daniel.is.fisc...@web.de>
Subject: Re: [Haskell-beginners] Re: Closure
To: beginners@haskell.org
Message-ID: <200908151831.14649.daniel.is.fisc...@web.de>
Content-Type: text/plain;  charset="iso-8859-15"

Am Samstag 15 August 2009 18:07:08 schrieb Daniel Bastos:
> In article <h65p0h$rj...@ger.gmane.org>,
>
> Heinrich Apfelmus wrote:
> > The simplest example of a closure is indeed
> >
> >    foo = add 3
> >
> > where
> >
> >    add = \x y -> x + y
>
> Question. This is actually equal to
>
> add x y = x + y
>
> But you wrote in terms of \. Why such preference?
>
> > Reduction to weak head normal form yields
> >
> >    foo = let x = 3 in \y -> x + y
> >
> > which means that  foo  is a function  \y -> x + y  paired with the value
> > of the free variable  x .
>
> I see.
>
> > Note that closures are an implementation detail. From a semantic point
> > of view,  add 3  can readily be understood as an ordinary function.
>
> This makes sense. Because, even in a language like C, a similar effect
> can be achieved, no? For example
>
> int plus(int x, int y) { return x + y; }
>
> int plus3(int y) { plus(3, y); }
>
> So, what I can't do in C, besides almost everything I can't do, is to
> do this nicely like I do in Haskell. But we don't call this a
> closure. In fact, we say C does not allow for closures. So what am I
> missing?
>

You can't do

cmp :: a -> a -> a -> Ordering
cmp pivot x y = ...

funkyFun :: (a -> a -> a -> Ordering) -> [a] -> [a]
funkyFun _ [] = []
funkyFun c (x:xs) = x:sortBy (c x) xs

main = do
    args <- getArgs
    print $ funkyFun cmp (some pseudorandom list depending on args)

in C (at least not without some black magic).

The plus3 example is a "closure" which is hardcoded and available at compile 
time.
I think, to say that a language allows closures means it allows closures 
determined at run 
time.


------------------------------

Message: 5
Date: Sat, 15 Aug 2009 12:34:25 -0400
From: "Brandon S. Allbery KF8NH" <allb...@ece.cmu.edu>
Subject: Re: [Haskell-beginners] Re: Closure
To: Daniel Bastos <dbasto...@toledo.com>
Cc: beginners@haskell.org
Message-ID: <1b14d870-7355-4efd-b0c6-026109ab4...@ece.cmu.edu>
Content-Type: text/plain; charset="us-ascii"

On Aug 15, 2009, at 12:07 , Daniel Bastos wrote:
> This makes sense. Because, even in a language like C, a similar effect
> can be achieved, no? For example
>
> int plus(int x, int y) { return x + y; }
>
> int plus3(int y) { plus(3, y); }
>
> So, what I can't do in C, besides almost everything I can't do, is to
> do this nicely like I do in Haskell. But we don't call this a
> closure. In fact, we say C does not allow for closures. So what am I
> missing?


In C you have to declare it.  In Haskell you can just do it on the fly:

 > map (add 3) [1..10]

or indeed

 > map (+3) [1..10]

(The above is actually a "section", a closure created from an infix  
function.  The difference is that I can specify either side of the  
operator, whereas to specify arguments other than the first for a  
regular function I must either coerce it into infix with `` or use the  
"flip" function to rearrange arguments.)

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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20090815/c71a43c5/PGP-0001.bin

------------------------------

Message: 6
Date: Sat, 15 Aug 2009 17:04:33 +0000 (UTC)
From: Daniel Bastos <dbasto...@toledo.com>
Subject: [Haskell-beginners] Re: Closure
To: beginners@haskell.org
Message-ID: <h66pr0$5m...@ger.gmane.org>

In article <1b14d870-7355-4efd-b0c6-026109ab4...@ece.cmu.edu>,
Brandon S. Allbery KF8NH wrote:

> In C you have to declare it.  

The word would be `define'?

> In Haskell you can just do it on the fly:
>
> > map (add 3) [1..10]

I see. Just like we can create an integer on the fly in C, in Haskell
we can create functions on the fly. I guess that's quite a difference.

> or indeed
>
> > map (+3) [1..10]
>
> (The above is actually a "section", a closure created from an infix  
> function.  The difference is that I can specify either side of the  
> operator, whereas to specify arguments other than the first for a  
> regular function I must either coerce it into infix with `` or use the  
> "flip" function to rearrange arguments.)

And is this mere syntax sugar?



------------------------------

Message: 7
Date: Sat, 15 Aug 2009 17:06:42 +0000 (UTC)
From: Daniel Bastos <dbasto...@toledo.com>
Subject: [Haskell-beginners] Re: Closure
To: beginners@haskell.org
Message-ID: <h66pv2$5m...@ger.gmane.org>

In article <200908151831.14649.daniel.is.fisc...@web.de>,
Daniel Fischer wrote:

> The plus3 example is a "closure" which is hardcoded and available at
> compile time.  I think, to say that a language allows closures means
> it allows closures determined at run time.

Hm. But does Haskell allow me to define a function at run time? I know
Lisp can, since a function is just a data structure which we can put
together at run time. But how about Haskell?



------------------------------

Message: 8
Date: Sat, 15 Aug 2009 21:14:39 +0200
From: Daniel Fischer <daniel.is.fisc...@web.de>
Subject: Re: [Haskell-beginners] Re: Closure
To: beginners@haskell.org
Message-ID: <200908152114.40077.daniel.is.fisc...@web.de>
Content-Type: text/plain;  charset="iso-8859-15"

Am Samstag 15 August 2009 19:06:42 schrieb Daniel Bastos:
> In article <200908151831.14649.daniel.is.fisc...@web.de>,
>
> Daniel Fischer wrote:
> > The plus3 example is a "closure" which is hardcoded and available at
> > compile time.  I think, to say that a language allows closures means
> > it allows closures determined at run time.
>
> Hm. But does Haskell allow me to define a function at run time? I know
> Lisp can, since a function is just a data structure which we can put
> together at run time. But how about Haskell?

Depends on how you interpret it.
In the sense of

... let foo = \y -> f x y in map foo list

where the value of x is supplied at run time (and more complicated 
constructions depending 
on run time values), sure.
If you write a good parser, you can also

do  putStrLn "Please enter function code:"
    code <- getLine
    let fun = parseFunction code
    use fun   -- may segfault if the entered code isn't good

In which (other) ways can you construct functions at run time in Lisp?




------------------------------

Message: 9
Date: Sat, 15 Aug 2009 19:12:43 -0500
From: Ian Duncan <iand...@gmail.com>
Subject: [Haskell-beginners] List combination function?
To: beginners <beginners@haskell.org>
Message-ID: <4a874efb.8020...@gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hello all,

I'm trying to build a function that takes a string such as "123" and 
gives me permutations including permutations with lesser list lengths. 
I'm not sure how to phrase it, but here is what the output could look like:

foo "123" => ["123","213","321","231","312","132", "12", "13", "21", 
"23", "31", "32", "1", "2", "3", ""]

The ordering doesn't matter, and that null list at the end doesn't 
particularly matter, but I don't really know the mathematical phrasing 
of what I'm asking for. I'm trying to build a scrabble helper that can 
find the optimal score given a set of letters to work with.

Thanks for your help,

Ian Duncan


------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 14, Issue 9
****************************************

Reply via email to