Re: [Haskell] Newbie

2013-03-08 Thread Henning Thielemann


On Thu, 7 Mar 2013, Dan Lior wrote:


Hello,

I'm new to Haskell and this is my first post to this forum.

A few questions right off the bat:

1) Is this the right place for newbies to post questions about Haskell?
2) Is there a FAQ for Haskell questions?


   http://www.haskell.org/haskellwiki/Category:FAQ


3) Are there any active Haskell user groups in the Chicago area?


I don't know, but user groups can be found at:
   http://www.haskell.org/haskellwiki/Category:Community

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


Re: [Haskell] Newbie

2013-03-07 Thread Ivan Lazar Miljenovic
On 8 March 2013 11:56, Brandon Allbery  wrote:
> On Thu, Mar 7, 2013 at 7:45 PM, Dan Lior  wrote:
>>
>> 1) Is this the right place for newbies to post questions about Haskell?
>
>
>
> This is most a list for announcements; beginn...@haskell.org is better for
> these kinds of questions, and haskell-c...@haskell.org for general
> discussion.
>
>> pred :: Int -> Int
>> pred 0 = 0
>> pred n+1 = n
>
>
> n+k patterns were part of Haskell '98, but removed from Haskell 2010. You
> may be able to use the pragma
>
> {-# LANGUAGE NPlusKPatterns #-}
>
> to turn them back on.

Even then, you need to have "pred (n+1) = n".

>
> --
> brandon s allbery kf8nh   sine nomine associates
> allber...@gmail.com  ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
>
> ___
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>



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

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


Re: [Haskell] Newbie

2013-03-07 Thread Brandon Allbery
On Thu, Mar 7, 2013 at 7:45 PM, Dan Lior  wrote:

> 1) Is this the right place for newbies to post questions about Haskell?
>


This is most a list for announcements; beginn...@haskell.org is better for
these kinds of questions, and haskell-c...@haskell.org for general
discussion.

pred :: Int -> Int
> pred 0 = 0
> pred n+1 = n
>

n+k patterns were part of Haskell '98, but removed from Haskell 2010. You
may be able to use the pragma

{-# LANGUAGE NPlusKPatterns #-}

to turn them back on.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] Newbie

2013-03-07 Thread Dan Lior
Hello, 

I'm new to Haskell and this is my first post to this forum. 

A few questions right off the bat:

1) Is this the right place for newbies to post questions about Haskell?
2) Is there a FAQ for Haskell questions? 
3) Are there any active Haskell user groups in the Chicago area?

A more technical question:

I'm messing around with basic Haskell examples on eclipse using the FP add-on 
running over GHC. 

The following code works:

pred :: Int -> Int
pred 0 = 0
pred n = n-1

The following code doesn't:

pred :: Int -> Int
pred 0 = 0
pred n+1 = n


Does anyone know why this might be? 

"Thanks" and "I apologize" in advance. 

dan



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


Re: [Haskell] Newbie help with type-classes

2007-05-11 Thread Derek Elkins

Ryan Ingram wrote:

[EMAIL PROTECTED] is better for this type of question.  Follow-up is set 
to it.


Here's a test case for the problem I'm having; I'm using runhaskell from 
ghc v6.6.
 
Problem #1) Without -fallow-undecidable-instances, I get the following 
error:

Constraint is no smaller than the instance head

This is bad.


Problem #2) With -fallow-undecidable-instances, I get this error instead:
Overlapping instances for ConvertToIntList ()


I don't understand why there is an overlapping instances error; () is 
not an instance of ConvertToInt so how could that instance ever apply?


I write anywhere, instance ConvertToInt () where ...
Now it is overlapping.

Is there something basic about type-classes that I'm not understanding 
here?  
They are open (Open World Assumption).  I can add a new instance anywhere at any 
time.



Code below:
{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}
 
module TestCase

where
 
class ConvertToInt a where

   conv :: a -> Int
 
class ConvertToIntList a where

   convl :: [a] -> [Int]
 
instance ConvertToInt Int where

   conv = id
 
instance ConvertToInt a => ConvertToIntList a where

This is what it's complaining about in the first error; this doesn't work.


   convl = map conv
 
instance ConvertToIntList () where

   convl x = []

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


Re: [Haskell] Newbie help with type-classes

2007-05-11 Thread Bas van Dijk

Maybe this is not what you want, but you can also put the 'convl'
function in the 'ConvertToInt' class.

class ConvertToInt a where
  conv  :: a -> Int
  convl :: [a] -> [Int]

With this approach you don't need any language extension.

regards,

Bas van Dijk

On 5/11/07, Ryan Ingram <[EMAIL PROTECTED]> wrote:

Here's a test case for the problem I'm having; I'm using runhaskell from ghc
v6.6.

Problem #1) Without -fallow-undecidable-instances, I get the following
error:
Constraint is no smaller than the instance head
  in the constraint: ConvertToInt a
(Use -fallow-undecidable-instances to permit this)
In the instance declaration for `ConvertToIntList a'

Problem #2) With -fallow-undecidable-instances, I get this error instead:
Overlapping instances for ConvertToIntList ()
  arising from use of `convl' at testcase.hs:28:6-15
Matching instances:
  instance (ConvertToInt a) => ConvertToIntList a
 -- Defined at testcase.hs:15:0
  instance ConvertToIntList () -- Defined at testcase.hs:18:0
In the expression: convl [()]
In the definition of `xl2': xl2 = convl [()]

I don't understand why there is an overlapping instances error; () is not an
instance of ConvertToInt so how could that instance ever apply?

Is there something basic about type-classes that I'm not understanding here?
 My actual problem is more complicated than this, but this test-case covers
the basic issue; something being an instance of class A means that I can
derive an instance of class B for it, but I want to implement other
instances of class B as well.

Code below:


{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}

module TestCase
where
 class ConvertToInt a where
   conv :: a -> Int

class ConvertToIntList a where
   convl :: [a] -> [Int]

instance ConvertToInt Int where
   conv = id

instance ConvertToInt a => ConvertToIntList a where
   convl = map conv

instance ConvertToIntList () where
   convl x = []

x :: Int
x = 5

xl :: [Int]
xl = convl [x]

xl2 :: [Int]
xl2 = convl [()]
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell



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


Re: [Haskell] Newbie help with type-classes

2007-05-11 Thread Bas van Dijk

Add: -fallow-overlapping-instances to your OPTIONS pragma and read
about overlapping instances in the GHC User Guide:

http://www.haskell.org/ghc/docs/latest/html/users_guide/type-extensions.html#instance-overlap

regards,

Bas van Dijk

On 5/11/07, Ryan Ingram <[EMAIL PROTECTED]> wrote:

Here's a test case for the problem I'm having; I'm using runhaskell from ghc
v6.6.

Problem #1) Without -fallow-undecidable-instances, I get the following
error:
Constraint is no smaller than the instance head
  in the constraint: ConvertToInt a
(Use -fallow-undecidable-instances to permit this)
In the instance declaration for `ConvertToIntList a'

Problem #2) With -fallow-undecidable-instances, I get this error instead:
Overlapping instances for ConvertToIntList ()
  arising from use of `convl' at testcase.hs:28:6-15
Matching instances:
  instance (ConvertToInt a) => ConvertToIntList a
 -- Defined at testcase.hs:15:0
  instance ConvertToIntList () -- Defined at testcase.hs:18:0
In the expression: convl [()]
In the definition of `xl2': xl2 = convl [()]

I don't understand why there is an overlapping instances error; () is not an
instance of ConvertToInt so how could that instance ever apply?

Is there something basic about type-classes that I'm not understanding here?
 My actual problem is more complicated than this, but this test-case covers
the basic issue; something being an instance of class A means that I can
derive an instance of class B for it, but I want to implement other
instances of class B as well.

Code below:


{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}

module TestCase
where
 class ConvertToInt a where
   conv :: a -> Int

class ConvertToIntList a where
   convl :: [a] -> [Int]

instance ConvertToInt Int where
   conv = id

instance ConvertToInt a => ConvertToIntList a where
   convl = map conv

instance ConvertToIntList () where
   convl x = []

x :: Int
x = 5

xl :: [Int]
xl = convl [x]

xl2 :: [Int]
xl2 = convl [()]
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell



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


[Haskell] Newbie help with type-classes

2007-05-10 Thread Ryan Ingram

Here's a test case for the problem I'm having; I'm using runhaskell from ghc
v6.6.

Problem #1) Without -fallow-undecidable-instances, I get the following
error:
   Constraint is no smaller than the instance head
 in the constraint: ConvertToInt a
   (Use -fallow-undecidable-instances to permit this)
   In the instance declaration for `ConvertToIntList a'
Problem #2) With -fallow-undecidable-instances, I get this error instead:
   Overlapping instances for ConvertToIntList ()
 arising from use of `convl' at testcase.hs:28:6-15
   Matching instances:
 instance (ConvertToInt a) => ConvertToIntList a
-- Defined at testcase.hs:15:0
 instance ConvertToIntList () -- Defined at testcase.hs:18:0
   In the expression: convl [()]
   In the definition of `xl2': xl2 = convl [()]
I don't understand why there is an overlapping instances error; () is not an
instance of ConvertToInt so how could that instance ever apply?

Is there something basic about type-classes that I'm not understanding
here?  My actual problem is more complicated than this, but this test-case
covers the basic issue; something being an instance of class A means that I
can derive an instance of class B for it, but I want to implement other
instances of class B as well.

Code below:
{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}

module TestCase
where

class ConvertToInt a where
  conv :: a -> Int

class ConvertToIntList a where
  convl :: [a] -> [Int]

instance ConvertToInt Int where
  conv = id

instance ConvertToInt a => ConvertToIntList a where
  convl = map conv

instance ConvertToIntList () where
  convl x = []

x :: Int
x = 5

xl :: [Int]
xl = convl [x]

xl2 :: [Int]
xl2 = convl [()]
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Newbie: fix

2007-05-02 Thread David House

On 02/05/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Hello,

could someone please explain why "fix" is necessary here:

fix (\f l -> if null l then [] else let (s,e) = break (==' ') l in s:f (drop 1
e))

Source: http://www.haskell.org/haskellwiki/Blow_your_mind


Because you're writing a recursive function. If you just had:

if null l then [] else let (s,e) = break (==' ') l in s:XXX (drop 1 e)

Then what goes in place of 'XXX'? There's no name for this particular
bit of code, so you can't call it. Using fix allows you to attach a
name to an arbitrary expression so that you can call it recursively.
The following would work exactly the same:

words :: String -> [String]
words l = if null l then [] else let (s,e) = break (==' ') l in
s:words (drop 1 e)

--
-David House, [EMAIL PROTECTED]
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] Newbie: fix

2007-05-02 Thread phiroc

Hello,

could someone please explain why "fix" is necessary here:

fix (\f l -> if null l then [] else let (s,e) = break (==' ') l in s:f (drop 1
e))

Source: http://www.haskell.org/haskellwiki/Blow_your_mind

Thanks.

phiroc
--- Begin Message ---
Hello,

could someone please explain why "fix" in necessary here:

fix (\f l -> if null l then [] else let (s,e) = break (==' ') l in s:f (drop 1
e))

Source: http://www.haskell.org/haskellwiki/Blow_your_mind

Thanks.

phiroc


--- End Message ---
Hello,

could someone please explain why "fix" in necessary here:

fix (\f l -> if null l then [] else let (s,e) = break (==' ') l in s:f (drop 1
e))

Source: http://www.haskell.org/haskellwiki/Blow_your_mind

Thanks.

phiroc


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


Re: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-28 Thread Udo Stenzel
[EMAIL PROTECTED] wrote:
> what are the advantages of haskell over semi-functional programming languages
> such as Perl, Common Lisp, etc.?

A fundamental building block that is superior in maintainability and
reusability to objects and procedures, a type system that is actually of
help and not a hindrance, and mathematical purity.


> What are the mysterious "side effects" which are avoided by using Haskell, 
> which
> everyone talks about? Null pointers?

Side effects are changes made to the environment by a procedure (beyond
returning its result), particularly those that you forgot about, that
get executed in the wrong order, and that change values under your feet
when you least expect it.

 
> Don't you ever get null pointers in Haskell, including when doing IO?

What's a pointer?  But we do get bottoms sometimes (rarely, the type
system often prevents you from stumbling over them), which is simply the
price you have to pay if you want a Turing-complete system.


> Aren't Haskell's advantages outweighed by its complexity (Monads, etc.) and
> rigidity?

You know about Design Patterns?  *Those* are complex.  Dozens of
Rube-Goldberg-Machines designed to circumvent inadequacies in languages
that should have been abandoned 20 years ago.  

If you try to apply the Design Patterns book to Haskell, half of the
patterns vanish, because they solve non-problems, most of the rest
becomes much simpler and only a few are added.  One particularly simple
new pattern is the Monad, which the gang of four couldn't discover for
lack of a language powerful enough to express it.  (Monad easily
subsumes Composite, generalizing and simplifying it in the process.  The
application of Monad to IO is straight forward, and then Monad also
subsumes Command.)

Btw, there's nothing rigid about Haskell.  I can adapt my Haskell code
much quicker to new requirements than is possible with either C or Perl,
and the Haskell code has the added benefit of still working after the
change.

 
> Last but not least, I would like to learn from those among you who are former
> PERL developers, why you switched to Haskell.

Because Perl is a royal PITA and Haskell is not.  Haskell also has no
inclination to yell "ARRAY(0xdeadbeef)" or "no method 5 in package
FooImpl" at me instead of producing sensible output (see also: type
system).


-Udo
-- 
I can ALWAYS build faster code if it doesn't have to work. (unknown source)


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


Re: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-28 Thread Robert Daniel Emerson
Dear Phiroc,

I am also a newbie to Haskell, but I also must confess having a sort of 
religious conversion. I also admit that the learning curve for Haskell, and 
in particular associated theory is steep, and I am only on the fist rung of 
the ladder. Some of what I say here has been echoed by others in answer to 
your query on the utility of Haskell.

I think most would agree that a language, be it natural or artificial, 
constrains or enhances they way you think, and perhaps even what you can 
think, and what you can create. Historically many technical problems remained 
intractable until the invention of the right language, the language of 
classical algebra, or the differential calculus I think are good common 
examples. Who would argue that Italian is a great language for operas?

I find even at the elementary level, many common algorithms seem to me 
naturally obvious when expressed in Haskell. Other have also pointed out that 
the category theory constructs that allow Haskell to remain a purely 
functional language, allow you to bring in 'the heavy guns' of standard 
mathematical reasoning. With out discussing what proof is really all about, 
it very powerful if that concept can be imported into the art of programming.

I also think that the relationship between parallel computing and functional 
languages will become  very important in to following decades as we hit 
'Moore's wall'.

Now for my real truth, it is just down right great fun, hacking at its best. 
If asked for a one line description on what Haskell is I would say that it is 
'Lisp on steroids'. Paul Graham has plenty to say about the utility and 
elegance of Lisp, I would like to know what he thinks of Haskell. I am going 
to paraphrase Graham: 'If a lot of really smart people are using something, 
and you can't see why, maybe its worth your time to see if you can see what 
they see'. Just to give you an idea of where I am coming from I started out 
putting food on the table in the 70's writing PDP 11 assembler programmes.

Suppose you don't even use Haskell in a project directly, maybe you develop 
your programme 'conceptually' in Haskell, and write it in whatever makes 
practical sense in your environment and market. You may end up with an 
artfully designed set of code, that is easier to maintain, with clear 
abstraction barriers.

In assaulting the learning curve I have found that I am building up a 
collection of texts, papers, blog postings, etc. If I don't understand one 
source, maybe another will give me some insight. I will just mention one of 
the many reference that I have found useful: 'Functional Programming - 
Practice and Theory' By Bruce J. MacLennan (ISBN 0-201-13744-5). Oh, and of 
course the classic, 'Structure and Interpretation of Computer Programs' by 
Ableson and Sussman. Neither is an 'Hakell' book, but I have found them 
hyper-useful for practical foundational material.

I would be interested to know what materials you are using to learn Haskell, 
and am glad to see that I am not the only 'newbie' :-)

Best Regards,
Robert Emerson

P.S. I didn't even mention Domain Specific Embedded Languages! Big time 
advantage.

On Friday 27 April 2007 01:02, [EMAIL PROTECTED] wrote:
> If this is interesting then please enlighten a poor, ignorant PERL hacker.
>
> Quoting Johannes Waldmann <[EMAIL PROTECTED]>:
> > [EMAIL PROTECTED] wrote:
> > > [...] semi-functional programming languages such as Perl [...]
> >
> > now this is an interesting view ...
>
> ___
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


RE: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-27 Thread Taillefer, Troy (EXP)
Java sense (i.e. "cut out any feature that can't be understood in five
minutes by a chimp")
 
Got to love comments like this they are constructive, objective, mature
and accurate. 
 
Glad we have your expert opinion to give us the gospel. 
 
Can I get an amen? How about a Hallelujah ?
 
Troy Taillefer Java chimpanzee

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Sebastian Sylvan
Sent: Thursday, April 26, 2007 1:27 PM
To: [EMAIL PROTECTED]
Cc: haskell@haskell.org
Subject: Re: [Haskell] Newbie: what are the advantages of Haskell?


(note to Haskellers: Yeah, I'm handwaving things here, no need to point
out counter-examples to my generalisations!)


On 4/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
We'll do this one first:


What are the mysterious "side effects" which are avoided by using
Haskell, which 
everyone talks about? Null pointers?


Side effects are usually things like mutable state. In Haskell variables
don't vary. "x=x+1" isn't valid in Haskell. This means, among other
things, that functions always do the same thing given the same input
(they can't depend on some mutable state changing value), which is great
since you'll never get those "oh I forgot that I must first call foo
before I call bar, or I'll get an error". This really is a HUGE win,
since programming with state is unreasonably error-prone. I'm afraid
it's next to impossible to convince anyone that this is true, unless
they're willing to give it a serious try, though :-) 

Null pointers are possible when you're dealing with C functions mostly.
You don't use pointers in Haskell normally, only when you're interfacing
with external C libraries etc.



Hello,

what are the advantages of haskell over semi-functional
programming languages
such as Perl, Common Lisp, etc.?


For me? Purity. I mean you can get plenty of the benefits of FP in any
old language (witness C# 3.0), but the one thing you can never get by
just adding support for a "functional style" in another language is
purity. Once purity is gone, it's gone! It can't be retrofitted on an
existing language.

Purity is great because it makes it much easier to write programs
without making silly mistakes. When writing programs in languages with
lots of side effects you have to sort of keep a "mental log" in your
head for all possible execution paths ("in this branch x is equal to y
plus w, and this pointer here is null in the other branch x is null
and..."). For me I can quite literally *feel* "brain resources" being
freed up when using Haskell, which I can use to get stuff done quicker
(or probably more accurate: I can feel how much brainpower I waste on
book keeping and keeping track of this "mental log" when using languages
like C++). 

Also purity is very interesting when you want to paralellize programs (a
pure function can be executed on any thread, at any time, and its
guaranteed to never interfer with the computation of other functions --
in impure languages this doesn't hold at all!). This is probably the
killer app for functional programming IMO. FP is cool for a number of
reasons, but I think "isn't almost unusable in a multithreaded setting"
is what sets it apart the most from imperative languages. 

Haskell also has STM which is great for that low level shared state
concurrency that you sometimes need (no locks, monitors, or any of that
non-composable, insanity-inducing, messiness!)
 



Aren't Haskell's advantages outweighed by its complexity
(Monads, etc.) and
rigidity?


I can sometimes feel that Haskell looses out on not being user friendly
in the Java sense (i.e. "cut out any feature that can't be understood in
five minutes by a chimp"). Some things do take some effort to learn, but
there is a huge payoff for it (it's really powerful!). But yeah, there
might be plenty of folks who will never bother learning about them, and
they won't understand your code. 
 



-- 
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862 
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-26 Thread Keith Fahlgren
On 4/26/07 10:13 AM, Joe Thornber wrote:
> On 26/04/07, Johannes Waldmann <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] wrote:
>>
>> > [...] semi-functional programming languages such as Perl [...]
>>
>> now this is an interesting view ...
> 
> I seem to remember someone writing a book on functional programming in
> Perl, which seemed odd to me.

For the record, you're probably thinking of Higher-Order Perl, by Mark Jason
Dominus.


HTH,
Keith

http://www.amazon.com/Higher-Order-Perl-Transforming-Programs/dp/1558607013
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


RE: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-26 Thread Taillefer, Troy (EXP)
Phiroc,

Hi Welcome to the mailing list.

Problem with partially functional languages in my opinion is if you can
do things the way that your most use i.e. imperative programming you
will do it

Perl, Python, Lisp, Scheme and etc have features that support functional
programming but I would wager that you will find more imperative code
written in those languages then you would functional code. People tend
to do things in the way there most accustom too and most developers are
educated in and work in imperative languages so if you really want to do
FP then your better to stick to a language that doesn't support other
more familiar paradigms otherwise you will find yourself falling back on
more comfortable and familiar ways of doing things.

Side effects include I/O, mutable assignment (destructively writing to
memory), generating random numbers etc.
Haskell of course has to allow these things otherwise it could not
produce useful programs it just does a lot better job of isolating these
side effects from Code
that does not have these side effects which have many benefits first
most being the ability to compose/glue code together in all sorts of
neat ways and not having to worry about unintentional side effects.

Advantage of Haskell over most other languages would be the core
language itself and its ability to glue software components together in
a safe way. This
advantage doesn't come without some pain and learning curve though.

Haskell is also a great language to learn new ideas and ways of thinking
about building software this is my interest in this language at this
time.

Haskell is a good place to start if you are looking to write something
from scratch
Unfortunately this is not my case. 

Disadvantages of Haskell are unfortunately greater then its advantages
as beautiful a programming language as Haskell is it lacks Libraries ( A
great glue language without many components to glue together is a sad
irony) and Tooling 

Haskell is not a language to get stuff done quickly in. I will probably
use Monads in a real world project in VB.NET 9 before Haskell.

I am not a Perl fan but CPAN is very cool when I have had to do
something in Perl I could find what I need there and it was well
documented too. 

Haskell to me is the promise of a dream yet unrealized in which you
easily glue together components together and it just works maybe one day
these components will actually get written.

Troy


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: Thursday, April 26, 2007 12:48 PM
To: haskell@haskell.org
Subject: [Haskell] Newbie: what are the advantages of Haskell?

Hello,

what are the advantages of haskell over semi-functional programming
languages such as Perl, Common Lisp, etc.?

What are the mysterious "side effects" which are avoided by using
Haskell, which everyone talks about? Null pointers?

Don't you ever get null pointers in Haskell, including when doing IO?

Aren't Haskell's advantages outweighed by its complexity (Monads, etc.)
and rigidity?

Last but not least, I would like to learn from those among you who are
former PERL developers, why you switched to Haskell.

Many thanks.

phiroc


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


Re: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-26 Thread mike clemow

Phiroc,

I'm new to these ideas too--especially since my college math training
is non-existent.  I found the following wikipedia articles
particularly illuminating on the topic of side-effects:

http://en.wikipedia.org/wiki/Side_effect_%28computer_science%29

and

http://en.wikipedia.org/wiki/Referential_transparency

FP is a completely different way of thinking about solving a problem
than is generally used in imperative programming.  It's a lot more
like math (see Alonso Church, Lambda Calculus, and Haskell Curry,
after which Haskell is named and the process called "Currying," ->
another great wikipedia read:  http://en.wikipedia.org/wiki/Currying
where some of the real power of FP comes from).

The main advantage to solving the problems in this way is that you can
be more sure (like mathematical proof kind of sure) that your program
does what it's intended to do.

As far as language vs language discussion, I say get a book, or look
on the net for a tutorial (try haskell.org for starters) and try it
out and see if it works for you.  That's what I'm doing.It's fun!
But, use the right tool for the job, of course, as Rob pointed out.

Cheers,
Mike (FP Ultra-Noob)


On 4/26/07, Sebastian Sylvan <[EMAIL PROTECTED]> wrote:

(note to Haskellers: Yeah, I'm handwaving things here, no need to point out
counter-examples to my generalisations!)

On 4/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
We'll do this one first:

What are the mysterious "side effects" which are avoided by using Haskell,
which
everyone talks about? Null pointers?

Side effects are usually things like mutable state. In Haskell variables
don't vary. "x=x+1" isn't valid in Haskell. This means, among other things,
that functions always do the same thing given the same input (they can't
depend on some mutable state changing value), which is great since you'll
never get those "oh I forgot that I must first call foo before I call bar,
or I'll get an error". This really is a HUGE win, since programming with
state is unreasonably error-prone. I'm afraid it's next to impossible to
convince anyone that this is true, unless they're willing to give it a
serious try, though :-)

Null pointers are possible when you're dealing with C functions mostly. You
don't use pointers in Haskell normally, only when you're interfacing with
external C libraries etc.

> Hello,
>
> what are the advantages of haskell over semi-functional programming
languages
> such as Perl, Common Lisp, etc.?

For me? Purity. I mean you can get plenty of the benefits of FP in any old
language (witness C# 3.0), but the one thing you can never get by just
adding support for a "functional style" in another language is purity. Once
purity is gone, it's gone! It can't be retrofitted on an existing language.

Purity is great because it makes it much easier to write programs without
making silly mistakes. When writing programs in languages with lots of side
effects you have to sort of keep a "mental log" in your head for all
possible execution paths ("in this branch x is equal to y plus w, and this
pointer here is null in the other branch x is null and..."). For me I can
quite literally *feel* "brain resources" being freed up when using Haskell,
which I can use to get stuff done quicker (or probably more accurate: I can
feel how much brainpower I waste on book keeping and keeping track of this
"mental log" when using languages like C++).

Also purity is very interesting when you want to paralellize programs (a
pure function can be executed on any thread, at any time, and its guaranteed
to never interfer with the computation of other functions -- in impure
languages this doesn't hold at all!). This is probably the killer app for
functional programming IMO. FP is cool for a number of reasons, but I think
"isn't almost unusable in a multithreaded setting" is what sets it apart the
most from imperative languages.

Haskell also has STM which is great for that low level shared state
concurrency that you sometimes need (no locks, monitors, or any of that
non-composable, insanity-inducing, messiness!)

>
> Aren't Haskell's advantages outweighed by its complexity (Monads, etc.)
and
> rigidity?

I can sometimes feel that Haskell looses out on not being user friendly in
the Java sense (i.e. "cut out any feature that can't be understood in five
minutes by a chimp"). Some things do take some effort to learn, but there is
a huge payoff for it (it's really powerful!). But yeah, there might be
plenty of folks who will never bother learning about them, and they won't
understand your code.



--
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell





--
http://clembie.livejournal.com
http://shadowofaculture.blogspot.com
http://deadlylittlepills.com
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/list

Re: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-26 Thread Rob Hoelz
[EMAIL PROTECTED] wrote:

> Hello,
> 
> what are the advantages of haskell over semi-functional programming
> languages such as Perl, Common Lisp, etc.?
> 
> What are the mysterious "side effects" which are avoided by using
> Haskell, which everyone talks about? Null pointers?
> 
> Don't you ever get null pointers in Haskell, including when doing IO?
> 
> Aren't Haskell's advantages outweighed by its complexity (Monads,
> etc.) and rigidity?
> 
> Last but not least, I would like to learn from those among you who
> are former PERL developers, why you switched to Haskell.
> 
> Many thanks.
> 
> phiroc
> 
> 
> ___
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell

There are plenty of advantages to Haskell; but it doesn't mean that
it's the only language I use now.  I read an article about Perl vs.
Python once, and the point that stuck with me most was "The Perl motto
is TMTOWTDI, and Python's just another WTDI."  The same applies to
Haskell, or any other language for that matter.  I love Haskell; my
code is usually bug-free (or close) the first time I run it because of
its features like having no side effects.  But I still use Perl for
system administration, and I'm developing a window manager in Scheme
now because of its features.

As far as Haskell's disadvantages, I don't see monads as a
disadvantage; most descriptions of them are complicated, but there are
plenty of good tutorials out there.  Rigidity is a double edged sword;
it helps keep your code working, but it does make you jump through some
hoops to get certain things working.

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


Re: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-26 Thread Sebastian Sylvan

(note to Haskellers: Yeah, I'm handwaving things here, no need to point out
counter-examples to my generalisations!)

On 4/26/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
We'll do this one first:

What are the mysterious "side effects" which are avoided by using Haskell,
which
everyone talks about? Null pointers?

Side effects are usually things like mutable state. In Haskell variables
don't vary. "x=x+1" isn't valid in Haskell. This means, among other things,
that functions always do the same thing given the same input (they can't
depend on some mutable state changing value), which is great since you'll
never get those "oh I forgot that I must first call foo before I call bar,
or I'll get an error". This really is a HUGE win, since programming with
state is unreasonably error-prone. I'm afraid it's next to impossible to
convince anyone that this is true, unless they're willing to give it a
serious try, though :-)

Null pointers are possible when you're dealing with C functions mostly. You
don't use pointers in Haskell normally, only when you're interfacing with
external C libraries etc.

Hello,


what are the advantages of haskell over semi-functional programming
languages
such as Perl, Common Lisp, etc.?



For me? Purity. I mean you can get plenty of the benefits of FP in any old
language (witness C# 3.0), but the one thing you can never get by just
adding support for a "functional style" in another language is purity. Once
purity is gone, it's gone! It can't be retrofitted on an existing language.

Purity is great because it makes it much easier to write programs without
making silly mistakes. When writing programs in languages with lots of side
effects you have to sort of keep a "mental log" in your head for all
possible execution paths ("in this branch x is equal to y plus w, and this
pointer here is null in the other branch x is null and..."). For me I can
quite literally *feel* "brain resources" being freed up when using Haskell,
which I can use to get stuff done quicker (or probably more accurate: I can
feel how much brainpower I waste on book keeping and keeping track of this
"mental log" when using languages like C++).

Also purity is very interesting when you want to paralellize programs (a
pure function can be executed on any thread, at any time, and its guaranteed
to never interfer with the computation of other functions -- in impure
languages this doesn't hold at all!). This is probably the killer app for
functional programming IMO. FP is cool for a number of reasons, but I think
"isn't almost unusable in a multithreaded setting" is what sets it apart the
most from imperative languages.

Haskell also has STM which is great for that low level shared state
concurrency that you sometimes need (no locks, monitors, or any of that
non-composable, insanity-inducing, messiness!)




Aren't Haskell's advantages outweighed by its complexity (Monads, etc.)
and
rigidity?



I can sometimes feel that Haskell looses out on not being user friendly in
the Java sense (i.e. "cut out any feature that can't be understood in five
minutes by a chimp"). Some things do take some effort to learn, but there is
a huge payoff for it (it's really powerful!). But yeah, there might be
plenty of folks who will never bother learning about them, and they won't
understand your code.




--
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-26 Thread Joe Thornber

On 26/04/07, Johannes Waldmann <[EMAIL PROTECTED]> wrote:

[EMAIL PROTECTED] wrote:

> [...] semi-functional programming languages such as Perl [...]

now this is an interesting view ...


I seem to remember someone writing a book on functional programming in
Perl, which seemed odd to me.

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


Re: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-26 Thread phiroc
If this is interesting then please enlighten a poor, ignorant PERL hacker.




Quoting Johannes Waldmann <[EMAIL PROTECTED]>:

> [EMAIL PROTECTED] wrote:
>
> > [...] semi-functional programming languages such as Perl [...]
>
> now this is an interesting view ...
>
>


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


Re: [Haskell] Newbie: what are the advantages of Haskell?

2007-04-26 Thread Johannes Waldmann

[EMAIL PROTECTED] wrote:


[...] semi-functional programming languages such as Perl [...]


now this is an interesting view ...

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


[Haskell] Newbie: what are the advantages of Haskell?

2007-04-26 Thread phiroc
Hello,

what are the advantages of haskell over semi-functional programming languages
such as Perl, Common Lisp, etc.?

What are the mysterious "side effects" which are avoided by using Haskell, which
everyone talks about? Null pointers?

Don't you ever get null pointers in Haskell, including when doing IO?

Aren't Haskell's advantages outweighed by its complexity (Monads, etc.) and
rigidity?

Last but not least, I would like to learn from those among you who are former
PERL developers, why you switched to Haskell.

Many thanks.

phiroc


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


Re: [Haskell] [newbie]any nice code to read?

2006-12-11 Thread 云杨

oh, sorry, I sent to a wrong mailing list.
I will ask for help there, thank you, and sorry for disturb you all.


On 12/12/06, Donald Bruce Stewart <[EMAIL PROTECTED]> wrote:


notyycn:
>
>hello,all,
>
>   I am new to haskell,and have read some tutorial, but I
>would like to read some "real" code from "real" haskell
>project, I believe this will help me study and use haskell
>quickly.
>
>  would anyone please give me some suggestion about
>opensource project that a new haskell user should study?

Visit:
   http://haskell.org

And click on 'Example code'

Also, new user questions are best asked on the haskell-cafe@haskell.org
mailing list.

Cheers,
Don

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


Re: [Haskell] [newbie]any nice code to read?

2006-12-11 Thread Donald Bruce Stewart
notyycn:
> 
>hello,all,
> 
>   I am new to haskell,and have read some tutorial, but I
>would like to read some "real" code from "real" haskell
>project, I believe this will help me study and use haskell
>quickly.
> 
>  would anyone please give me some suggestion about
>opensource project that a new haskell user should study?

Visit:
http://haskell.org

And click on 'Example code'

Also, new user questions are best asked on the haskell-cafe@haskell.org
mailing list.

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


[Haskell] [newbie]any nice code to read?

2006-12-11 Thread 云杨

hello,all,
  I am new to haskell,and have read some tutorial, but I would like to read
some "real" code from "real" haskell project, I believe this will help me
study and use haskell quickly.
 would anyone please give me some suggestion about opensource project that
a new haskell user should study?
 thanks you.
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Newbie quick questions

2005-10-05 Thread Collin Winter
On 10/4/05, Mike Crowe <[EMAIL PROTECTED]> wrote:
>  This may be unfair to ask, but is anybody willing to give an example?
> There are great examples for writing factorials.  However, that's not really
> useful.  I'm looking for a real-world example of using the language.

You might be interested in Dazzle [1], which I recently read up on.
It's a Bayesian network toolbox written in Haskell and using wxHaskell
for the GUI side. The team behind it had a paper [2] accepted to the
2005 Haskell Workshop that details some of the tricks they used to do
the GUI integration.

Hope this helps.

Collin Winter

[1] http://www.cs.uu.nl/dazzle/
[2] http://www.cs.uu.nl/dazzle/f08-schrage.pdf
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Newbie quick questions

2005-10-05 Thread Sebastian Sylvan
On 10/5/05, Sebastian Sylvan <[EMAIL PROTECTED]> wrote:
> On 10/4/05, Mike Crowe <[EMAIL PROTECTED]> wrote:
> >  Thanks, all, especially Cale for the detail.
> >
> >  This may be unfair to ask, but is anybody willing to give an example?
> > There are great examples for writing factorials.  However, that's not really
> > useful.  I'm looking for a real-world example of using the language.
> > Specifically, the first page of About Haskell states:
> > WOW! I basically wrote this without testing just thinking about my program
> > in terms of transformations between types. What I'm still missing is how to
> > use this idea of functional programming to tie all this together.  Let's
> > say, for example, I want to write a data input system for a database.
> > Consider these two examples:
> >
> >  I think I understand how to take the following example (and others in that
> > library) and expand to a complete UI for the data input:
> > http://cvs.sourceforge.net/viewcvs.py/wxhaskell/wxhaskell/samples/wx/Grid.hs?rev=1.6&view=auto
> >
> >  I also looked over the examples in
> > http://htoolkit.sourceforge.net/ for writing to a SQL
> > database.  So I can see how to save the data.  The following example I get
> > for inserting:
> >  insertRecords :: Connection -> IO ()
> >  insertRecords c = do
> >  execute c "insert into Test(id,name) values (1,'Test1')"
> >
> >  How, though, would I start?  If I did this in an imperative language, I
> > might do it like (in Python):
> >
> >  def main:
> >  if gridCtrl.Show():# returns True if user exits
> > pressing Save
> >  data = gridCtrl.getData()
> >  dataBase.insertRecords(data)
> >
> >  In Haskell, how would you start this at the top?  How would you define a
> > relationship between two modules?
> >
> >  If this is more detailed than I should ask in this list, please LMK.
> >
> >  Thanks!
> >  Mike
>
> In general you write a small "shell" of IO code as your base
> application. This IO code then calls the rest of the
> (non-IO-)functions and presents the result in some way.
>
> As you can see in the source code you linked you can attatch IO
> actions to events. E.g.
> set g [on gridEvent := onGrid]
>
> So to, for example, trigger a database update when the user presses a
> button, you would attatch the database-update action to the on click
> event for that button.
>
> You could also use partial application to pass along extra data that
> this function may need
>
> set but [on click := updateDB dbConnection]
>
> where dbConnection is some value representing a database connection
>
> and then in the function defintion:
>
> updateDB dbConn  =  do ...
>
> As you can see onGrid takes two parameters (everything it needs to do
> what you want it to do) but when you attatch it to the gridEvent you
> only pass it the first one (the event itself passes the second one).

I meant updateDB and click-event and there respectively. Sorry.

/S

--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Newbie quick questions

2005-10-05 Thread Sebastian Sylvan
On 10/4/05, Mike Crowe <[EMAIL PROTECTED]> wrote:
>  Thanks, all, especially Cale for the detail.
>
>  This may be unfair to ask, but is anybody willing to give an example?
> There are great examples for writing factorials.  However, that's not really
> useful.  I'm looking for a real-world example of using the language.
> Specifically, the first page of About Haskell states:
> WOW! I basically wrote this without testing just thinking about my program
> in terms of transformations between types. What I'm still missing is how to
> use this idea of functional programming to tie all this together.  Let's
> say, for example, I want to write a data input system for a database.
> Consider these two examples:
>
>  I think I understand how to take the following example (and others in that
> library) and expand to a complete UI for the data input:
> http://cvs.sourceforge.net/viewcvs.py/wxhaskell/wxhaskell/samples/wx/Grid.hs?rev=1.6&view=auto
>
>  I also looked over the examples in
> http://htoolkit.sourceforge.net/ for writing to a SQL
> database.  So I can see how to save the data.  The following example I get
> for inserting:
>  insertRecords :: Connection -> IO ()
>  insertRecords c = do
>  execute c "insert into Test(id,name) values (1,'Test1')"
>
>  How, though, would I start?  If I did this in an imperative language, I
> might do it like (in Python):
>
>  def main:
>  if gridCtrl.Show():# returns True if user exits
> pressing Save
>  data = gridCtrl.getData()
>  dataBase.insertRecords(data)
>
>  In Haskell, how would you start this at the top?  How would you define a
> relationship between two modules?
>
>  If this is more detailed than I should ask in this list, please LMK.
>
>  Thanks!
>  Mike

In general you write a small "shell" of IO code as your base
application. This IO code then calls the rest of the
(non-IO-)functions and presents the result in some way.

As you can see in the source code you linked you can attatch IO
actions to events. E.g.
set g [on gridEvent := onGrid]

So to, for example, trigger a database update when the user presses a
button, you would attatch the database-update action to the on click
event for that button.

You could also use partial application to pass along extra data that
this function may need

set but [on click := updateDB dbConnection]

where dbConnection is some value representing a database connection

and then in the function defintion:

updateDB dbConn  =  do ...

As you can see onGrid takes two parameters (everything it needs to do
what you want it to do) but when you attatch it to the gridEvent you
only pass it the first one (the event itself passes the second one).
You would most likely want to pass other data to updateDB, such as the
data that should be inserted into the table etc. You could e.g. pass
the gridcontrol to updateDB and let the updateDB function extract the
data from it and insert it into the database.

So the main IO code is very imperative in look and feel, except that
all data flow is explicit (and perhaps more importantly, that actions
are first class citizens). So you could lay out your haskell IO code
in much the same way as you would in an imperative language.

As an aside. if you're going to use databases, consider using
HaskellDB (an SQL "unwrapper"), which allows you type-safe database
queries (pretty cool!).

/S

--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Newbie quick questions

2005-10-04 Thread Mike Crowe




Thanks, all, especially Cale for the detail.

This may be unfair to ask, but is anybody willing to give an example? 
There are great examples for writing factorials.  However, that's not
really useful.  I'm looking for a real-world example of using the
language.  Specifically, the first page of About Haskell states: 
WOW! I basically wrote this without testing
just thinking about my
program in terms of transformations between types. 
What I'm still missing is how to use this idea of functional
programming to tie all this together.  Let's say, for example, I want
to write a data input system for a database.  Consider these two
examples:

I think I understand how to take the following example (and others in
that library) and expand to a complete UI for the data input:
http://cvs.sourceforge.net/viewcvs.py/wxhaskell/wxhaskell/samples/wx/Grid.hs?rev=1.6&view=auto

I also looked over the examples in http://htoolkit.sourceforge.net/
for writing to a SQL database.  So I can see how to save the data.  The
following example I get for inserting:
insertRecords :: Connection -> IO ()
insertRecords c = do
    execute c "insert into Test(id,name) values (1,'Test1')"

How, though, would I start?  If I did this in an imperative language, I
might do it like (in Python):

def main:
    if gridCtrl.Show():                        # returns True if user
exits pressing Save
        data = "">
        dataBase.insertRecords(data)

In Haskell, how would you start this at the top?  How would you define
a relationship between two modules?

If this is more detailed than I should ask in this list, please LMK.

Thanks!
Mike


Signature




Cale Gibbard wrote:

  I wouldn't really consider any of those a particularly quick question,
but I'll give them a shot :)

On 04/10/05, Mike Crowe <[EMAIL PROTECTED]> wrote:
  
  
Hi folks,

I ran across Haskell at the Great Win32 Computer Language Shootout.  A
friend approached me with a potential large application to develop.  The
idea of a language which can reduce time to design and make better code
is very intriguing.

I was looking at prototyping in Python using wxWindows as the GUI.  I
see Haskell has wxWindows libraries as well.

So, here's some newbie questions I couldn't get from 2-3h on the various
web sites:

1) Can I develop a Windows application to sell?  Or is Haskell not
really geared for that?

  
  
Well, of course -- the compilers are free, but there's no reason I can
see that you couldn't sell an app that was written in Haskell. You'd
need to be careful about the licenses of libraries that you use. I
think that binaries produced with GHC are currently linked with libgmp
which is under the LGPL, so you may have to be careful there as well.
There are a variety of cross platform GUI libraries available.

  
  
2) Say a team wants to develop a larger application, like a CRM system.
In "thinking" in functional programming, can a team split up work and
implementation and work together?  In other words, how easily does
Haskell adapt to a team approach?

  
  
Haskell supports quite a few different abstractions which would let
you code things separately. In fact, most Haskell code is
referentially transparent, so you usually don't even need the rest of
the app to run in order to properly test a particular function (just
the dependencies of that function). The type system is very nice at
eliminating potential for bugs and helping to document how things fit
together.

The largest application that I've written personally is a pipeline
scheduler and register allocator as part of a compiler for a high
level signal processing language. The algorithm was a search and
backtracking algorithm, which carried on into the register allocation
(if a schedule couldn't be register allocated, it would have to
backtrack into the scheduler). A nice thing here is that I didn't have
to think of it as such, as all the backtracking occurred
automatically, as I used the list monad for nondeterminism. After
design of the algorithm which would be used, it only took a couple
weeks to implement and test and was around 1000 lines, which was about
1/2 documentation, and ~250 lines of which was a parser generator for
an assembly/dependency language, which built a parser based on the
opcodes available. I suspect that a similar project in C would be at
least 10 times as much code, and would not have been manageable in the
time I had.

Many things are very elegantly expressed in Haskell. I recommend that
you try writing some small applications in it to get a feel for what
it's like.

  
  
3) Again, using a CRM tool as an example, what is the advantage to
developing an application like this in Haskell vs. any other language?
If I really invest the time, can I get this done quicker in Haskell?
Sell me on this, please.

  
  
Haskell has quite a lot of nice features which help in various
different ways. I won't even try to list them all for you, but point
out a few I find nice. This really takes

Re: [Haskell] Newbie quick questions

2005-10-04 Thread Cale Gibbard
I wouldn't really consider any of those a particularly quick question,
but I'll give them a shot :)

On 04/10/05, Mike Crowe <[EMAIL PROTECTED]> wrote:
> Hi folks,
>
> I ran across Haskell at the Great Win32 Computer Language Shootout.  A
> friend approached me with a potential large application to develop.  The
> idea of a language which can reduce time to design and make better code
> is very intriguing.
>
> I was looking at prototyping in Python using wxWindows as the GUI.  I
> see Haskell has wxWindows libraries as well.
>
> So, here's some newbie questions I couldn't get from 2-3h on the various
> web sites:
>
> 1) Can I develop a Windows application to sell?  Or is Haskell not
> really geared for that?

Well, of course -- the compilers are free, but there's no reason I can
see that you couldn't sell an app that was written in Haskell. You'd
need to be careful about the licenses of libraries that you use. I
think that binaries produced with GHC are currently linked with libgmp
which is under the LGPL, so you may have to be careful there as well.
There are a variety of cross platform GUI libraries available.

> 2) Say a team wants to develop a larger application, like a CRM system.
> In "thinking" in functional programming, can a team split up work and
> implementation and work together?  In other words, how easily does
> Haskell adapt to a team approach?

Haskell supports quite a few different abstractions which would let
you code things separately. In fact, most Haskell code is
referentially transparent, so you usually don't even need the rest of
the app to run in order to properly test a particular function (just
the dependencies of that function). The type system is very nice at
eliminating potential for bugs and helping to document how things fit
together.

The largest application that I've written personally is a pipeline
scheduler and register allocator as part of a compiler for a high
level signal processing language. The algorithm was a search and
backtracking algorithm, which carried on into the register allocation
(if a schedule couldn't be register allocated, it would have to
backtrack into the scheduler). A nice thing here is that I didn't have
to think of it as such, as all the backtracking occurred
automatically, as I used the list monad for nondeterminism. After
design of the algorithm which would be used, it only took a couple
weeks to implement and test and was around 1000 lines, which was about
1/2 documentation, and ~250 lines of which was a parser generator for
an assembly/dependency language, which built a parser based on the
opcodes available. I suspect that a similar project in C would be at
least 10 times as much code, and would not have been manageable in the
time I had.

Many things are very elegantly expressed in Haskell. I recommend that
you try writing some small applications in it to get a feel for what
it's like.

> 3) Again, using a CRM tool as an example, what is the advantage to
> developing an application like this in Haskell vs. any other language?
> If I really invest the time, can I get this done quicker in Haskell?
> Sell me on this, please.

Haskell has quite a lot of nice features which help in various
different ways. I won't even try to list them all for you, but point
out a few I find nice. This really takes some exploring on your own in
order to find out what is available, and how it might help. Also keep
in mind that a lot has been written on the wiki
(http://www.haskell.org/hawiki/) and in these mailing lists as to neat
ways in which to use Haskell's features.

Referential transparency I already mentioned, is incredibly nice to
have. It basically consists of the guarantee that functions are
completely determined by what values they return for given inputs -
there is no hidden global state or side effects. This makes it much
easier to prove that programs do what they are supposed to do, as well
as to understand the code.

The type system itself is marvellous in its ability to control how
code is used and catch bugs at compile time, and prove various simple
constraints hold on the code. To a very large extent, when programs
compile, they also work as intended. Of course there are still bugs
involved with using the wrong algorithm, but nothing can really
prevent that. The type system catches a large portion of the errors
which occur from attempting to fit existing pieces of code together in
an unsuitable way.

This is incredibly helpful when approaching a large library of
existing code and wanting to write a new function based on it. The
first thing to do is to look at the type of the function you want to
write, and the types of the functions available. Your options in
searching for useful code will often be quite restricted by the types
which makes your job easier.

When state and side effects are needed in Haskell, these things
(though not only these things) are treated specially through the use
of monads, which are a nice abstraction of both containers and

Re: [Haskell] Newbie quick questions

2005-10-04 Thread Duncan Coutts
On Tue, 2005-10-04 at 11:31 +0100, Jon Fairbairn wrote:
> On 2005-10-04 at 00:01EDT Mike Crowe wrote:
> > Hi folks,
> > 
> > I ran across Haskell at the Great Win32 Computer Language Shootout.  A 
> > friend approached me with a potential large application to develop.  The 
> > idea of a language which can reduce time to design and make better code 
> > is very intriguing.
> 
> > 1) Can I develop a Windows application to sell?  Or is Haskell not 
> > really geared for that?
> 
> I don't see any reason why not, though the GUI aspect of
> Haskell is as well developed as some other aspects of the 
> language.

Gtk2Hs and wxHaskell both support Windows and both are distributed under
the LGPL (or a license very similar to the LGPL) so are suitable for
developing proprietary applications.

Both libraries are nearing maturity; both are approaching 1.0 releases.

http://haskell.org/gtk2hs/
http://wxhaskell.sourceforge.net/

Duncan

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


Re: [Haskell] Newbie quick questions

2005-10-04 Thread Jon Fairbairn
On 2005-10-04 at 00:01EDT Mike Crowe wrote:
> Hi folks,
> 
> I ran across Haskell at the Great Win32 Computer Language Shootout.  A 
> friend approached me with a potential large application to develop.  The 
> idea of a language which can reduce time to design and make better code 
> is very intriguing.

> 1) Can I develop a Windows application to sell?  Or is Haskell not 
> really geared for that?

I don't see any reason why not, though the GUI aspect of
Haskell is as well developed as some other aspects of the 
language.

> 2) Say a team wants to develop a larger application, like a CRM system.  
> In "thinking" in functional programming, can a team split up work and 
> implementation and work together?  In other words, how easily does 
> Haskell adapt to a team approach?

At least as well as any other language.

> 3) Again, using a CRM tool as an example, what is the advantage to 
> developing an application like this in Haskell vs. any other language?  
> If I really invest the time, can I get this done quicker in Haskell?  
> Sell me on this, please.

Whether you can get it done quicker depends on how long it
takes you to "get" functional programming. It's very easy to
understand Haskell just well enough to write C programmes in
it. It takes a significantly greater effort -- and time --
to get into the appropriate state of mind to write real
Haskell programmes.

> 3) I'm a very top-down programmer.  I like to start at the "big-picture" 
> and work my way down in implementation.  Does this adapt to Haskell, or 
> am I missing the point?

Haskell is very good for this.


-- 
Jón Fairbairn  Jon.Fairbairn at cl.cam.ac.uk


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


[Haskell] Newbie quick questions

2005-10-03 Thread Mike Crowe

Hi folks,

I ran across Haskell at the Great Win32 Computer Language Shootout.  A 
friend approached me with a potential large application to develop.  The 
idea of a language which can reduce time to design and make better code 
is very intriguing.


I was looking at prototyping in Python using wxWindows as the GUI.  I 
see Haskell has wxWindows libraries as well.


So, here's some newbie questions I couldn't get from 2-3h on the various 
web sites:


1) Can I develop a Windows application to sell?  Or is Haskell not 
really geared for that?
2) Say a team wants to develop a larger application, like a CRM system.  
In "thinking" in functional programming, can a team split up work and 
implementation and work together?  In other words, how easily does 
Haskell adapt to a team approach?
3) Again, using a CRM tool as an example, what is the advantage to 
developing an application like this in Haskell vs. any other language?  
If I really invest the time, can I get this done quicker in Haskell?  
Sell me on this, please.
3) I'm a very top-down programmer.  I like to start at the "big-picture" 
and work my way down in implementation.  Does this adapt to Haskell, or 
am I missing the point?


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


Re: [Haskell] [Newbie] Data structure for Dijkstra's algorithm

2005-02-15 Thread Josef Svenningsson
On Mon, 14 Feb 2005 12:27:51 -0500, robert dockins
<[EMAIL PROTECTED]> wrote:
> [Dijkstra's] algorithm relies pretty fundamentally on mutability, which makes 
> it
>   a less than wonderful fit for a functional language.  If you want to
> use this algorithm in particular, I would recommend a mutable array
> indexed on the vertex pair (u,v).

It is quite possible to implement the shortest path algorithm
functionally even though it is not straight forward. See the following
paper by Ralf Hinze:
http://www.informatik.uni-bonn.de/~ralf/publications/ICFP01.pdf

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


Re: [Haskell] [Newbie] Data structure for Dijkstra's algorithm

2005-02-15 Thread Pedro Vasconcelos
On Mon, 14 Feb 2005 15:00:17 +0100
RCP-Software <[EMAIL PROTECTED]> wrote:

> For input and output I need an appropriate graph representation. It 
> should be as simple to implement as possible - speed and memory 
> consumption does not matter. The graph consists of vertices (including 
> the source vertex) and weighted edges. I first thought of an adjacency 
> matrix implemented with nested lists. Something like
>   [[0,1,6,2] , [1,0,2,infinity] , [6,2,0,3] , [2,infinity,3,0]]
> where every sublist represents a vertex, and every entry represents the 
> edge weight to another vertex (infinity means there is no direct 
> connection, and 0 means it points to itself).

Robert, if you're not requiring an efficient implementation you can
represent the graph as a list of (weighted) arcs, i.e.

type Node =  Int -- or whatever you want to label the nodes with
type Weight = Int-- weights are just ints 
type Arc = (Node, Weight, Node)
type Graph = [Arc]

The type name declarations are just for readability, but also to enforce
that you keep nodes and weights separately (even thought they might both
be integers).

Alternatively, you could also use an adjecency list, but again you
should distinguish nodes and weights:

type Adj = [(Node,Weight)] -- weighted arcs connecting to nodes 
type AdjGraph = [ (Node, Adj) ]-- list of adjecencies

In either case, remember that Haskell lists must be homogenous, i.e. you
can't have a weight being either an int or "infinity". You can either
use a special  large value to represent infinity or you'd have to define
a lifted type. I'd recomend you try the first option first.

BTW, these represetations are less efficient than you could write in
e.g. C because you have to traverse a list to find neighbours of a
vertex. It is possible to write more efficient representation using
references or arrays, but I'd stay away from that until you're more
familiar with the language.

Best regards,

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


Re: [Haskell] [Newbie] Data structure for Dijkstra's algorithm

2005-02-14 Thread ajb
G'day all.

Quoting robert dockins <[EMAIL PROTECTED]>:

> This algorithm relies pretty fundamentally on mutability, which makes it
>   a less than wonderful fit for a functional language.

Right, which makes me wonder if this is the algorithm that you really want.

Does it have to be Dijkstra's algorithm?  Dynamic programming algorithms
(e.g. the Floyd-Warshall algorithm) are very easy to write in a lazy
language like Haskell, because you don't need mutability; you write
"thunks" into a dictionary data structure (which may depend on other
values in the data structure), and let the evaluation rule do the rest.

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


Re: [Haskell] [Newbie] Data structure for Dijkstra's algorithm

2005-02-14 Thread robert dockins
This algorithm relies pretty fundamentally on mutability, which makes it 
 a less than wonderful fit for a functional language.  If you want to 
use this algorithm in particular, I would recommend a mutable array 
indexed on the vertex pair (u,v).  See:

http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data.Array.MArray.html
These will require your program to be in the IO or ST monads. 
Alternately, you could do it fully functionally using Data.FiniteMap, 
but I don't think you will be happy with the performance.

If you just want to solve the shortest path problem, it may be possible 
to come up with something using the Data.Graph module, although you 
might have to dig around in the module source to get at what you need. 
There's a lot of goodies not exported from that module.


RCP-Software wrote:
Hi!
I am new to functional Programming and need some advice. I want to 
implement Dijkstra's algorithm for the shortest path problem. The 
algorithm calculates the shortest path from a single vertex in a 
directed graph to any other connected vertex ( 
http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm ).

For input and output I need an appropriate graph representation. It 
should be as simple to implement as possible - speed and memory 
consumption does not matter. The graph consists of vertices (including 
the source vertex) and weighted edges. I first thought of an adjacency 
matrix implemented with nested lists. Something like
[[0,1,6,2] , [1,0,2,infinity] , [6,2,0,3] , [2,infinity,3,0]]
where every sublist represents a vertex, and every entry represents the 
edge weight to another vertex (infinity means there is no direct 
connection, and 0 means it points to itself).
My main problem is that this adjacency list is not so easy to process. 
For my output I need a tree like structure and I always need to keep 
track of the previous vertex and its distance etc. Other approaches e.g. 
structure-like tuples didn't really work - my C experience is worthless.

Bottom line - I don't what to do. Any help is appreciated.
TIA, Robert Potthast
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] [Newbie] Data structure for Dijkstra's algorithm

2005-02-14 Thread RCP-Software
Hi!
I am new to functional Programming and need some advice. I want to 
implement Dijkstra's algorithm for the shortest path problem. The 
algorithm calculates the shortest path from a single vertex in a 
directed graph to any other connected vertex ( 
http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm ).

For input and output I need an appropriate graph representation. It 
should be as simple to implement as possible - speed and memory 
consumption does not matter. The graph consists of vertices (including 
the source vertex) and weighted edges. I first thought of an adjacency 
matrix implemented with nested lists. Something like
	[[0,1,6,2] , [1,0,2,infinity] , [6,2,0,3] , [2,infinity,3,0]]
where every sublist represents a vertex, and every entry represents the 
edge weight to another vertex (infinity means there is no direct 
connection, and 0 means it points to itself).
My main problem is that this adjacency list is not so easy to process. 
For my output I need a tree like structure and I always need to keep 
track of the previous vertex and its distance etc. Other approaches 
e.g. structure-like tuples didn't really work - my C experience is 
worthless.

Bottom line - I don't what to do. Any help is appreciated.
TIA, Robert Potthast
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Newbie : How come that cyclic recursive lists are efficient ?

2005-01-24 Thread Benjamin Franksen
On Monday 24 January 2005 21:47, Francis Girard wrote:
> But I can't help thinking that the distinction between "being" a list of
> integers and "being" a function that "returns" a list of integers (without
> arguments) is not always clear in FP ... since there is not really such a
> thing as returning a value in declarative programming, neither in
> mathematical thinking.

There *is no* difference between the two if one views them as pure 
mathematical values. Questions of run time speed or memory usage, i.e. 
efficiency (which your original question was about) are clearly outside the 
realm of pure values, and thus we may perceive them as distinct in this wider 
setting.

My favourite analogy for this is the old joke about a topologist being a 
person who cannot see any difference between a cup and a doghnut.

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


Re: [Haskell] Newbie : How come that cyclic recursive lists are efficient ?

2005-01-24 Thread Francis Girard
Thank you,

I understand the point.

But I can't help thinking that the distinction between "being" a list of 
integers and "being" a function that "returns" a list of integers (without 
arguments) is not always clear in FP ... since there is not really such a 
thing as returning a value in declarative programming, neither in 
mathematical thinking.

Thank you

Francis Girard
FRANCE

Le lundi 24 Janvier 2005 18:11, Graham Klyne a écrit :
> Notice that 'hamming' *is* a list of integers, not a function to produce
> them:
>
>hamming :: [Integer]
>
> Thus, the "magic" here is that you can define this list as a value, without
> having to actually evaluate any element until it's needed, either by direct
> reference from another function, or indirectly by the recursive definition
> to obtain a value directly required.  But once evaluated, the deferred
> evaluation is replaced by the resulting value.
>
> This is the power of lazy evaluation.  Even  fixed values (as opposed to
> function calls) aren't evaluated until they're needed.
>
> #g
> --
>
> At 10:38 24/01/05 +0100, Francis Girard wrote:
> >Hi,
> >
> >The classical Hamming problem have the following solution in Haskell :
> >
> >*** BEGIN SNAP
> >-- hamming.hs
> >
> >-- Merges two infinite lists
> >merge :: (Ord a) => [a] -> [a] -> [a]
> >merge (x:xs)(y:ys)
> >
> >   | x == y= x : merge xs ys
> >   | x <  y= x : merge xs (y:ys)
> >   | otherwise = y : merge (x:xs) ys
> >
> >-- Lazily produce the hamming sequence
> >hamming :: [Integer]
> >hamming
> >   = 1 : merge (map (2*) hamming) (merge (map (3*) hamming) (map (5*)
> > hamming))
> >*** END SNAP
> >
> >I just love these algorithms that run after their tail (they make my brain
> >melt) but I don't know how is it that they are efficient.
> >
> >Here, the hamming recursively calls itself three times. For this algorithm
> > to be efficient, the Haskell system, somehow, has to "remember" the
> > already generated sequence THROUGH RECURSION (i.e. not only intermediate
> > "local" results) otherwise it would end up regenerating the beginning of
> > the sequence over and over again.
> >
> >Obviously, Haskell does remember what had already been generated THROUGH
> >RECURSION since executing the program with GHCI runs quite smoothly and
> >responsively.
> >
> >That Haskell manages to do that is for me "magnifique". But I need to know
> >(if
> >only a little) about how it achieves this in order to know what I, as a
> >lambda programmer, can do, and how to compute the Big-Oh complexity of the
> >algorithm.
> >
> >Thank you,
> >
> >Francis Girard
> >FRANCE
> >
> >___
> >Haskell mailing list
> >Haskell@haskell.org
> >http://www.haskell.org/mailman/listinfo/haskell
>
> 
> Graham Klyne
> For email:
> http://www.ninebynine.org/#Contact
>
> ___
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell

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


Re: [Haskell] Newbie : How come that cyclic recursive lists are efficient ?

2005-01-24 Thread Graham Klyne
Notice that 'hamming' *is* a list of integers, not a function to produce them:
  hamming :: [Integer]
Thus, the "magic" here is that you can define this list as a value, without 
having to actually evaluate any element until it's needed, either by direct 
reference from another function, or indirectly by the recursive definition 
to obtain a value directly required.  But once evaluated, the deferred 
evaluation is replaced by the resulting value.

This is the power of lazy evaluation.  Even  fixed values (as opposed to 
function calls) aren't evaluated until they're needed.

#g
--
At 10:38 24/01/05 +0100, Francis Girard wrote:
Hi,
The classical Hamming problem have the following solution in Haskell :
*** BEGIN SNAP
-- hamming.hs
-- Merges two infinite lists
merge :: (Ord a) => [a] -> [a] -> [a]
merge (x:xs)(y:ys)
  | x == y= x : merge xs ys
  | x <  y= x : merge xs (y:ys)
  | otherwise = y : merge (x:xs) ys
-- Lazily produce the hamming sequence
hamming :: [Integer]
hamming
  = 1 : merge (map (2*) hamming) (merge (map (3*) hamming) (map (5*) 
hamming))
*** END SNAP

I just love these algorithms that run after their tail (they make my brain
melt) but I don't know how is it that they are efficient.
Here, the hamming recursively calls itself three times. For this algorithm to
be efficient, the Haskell system, somehow, has to "remember" the already
generated sequence THROUGH RECURSION (i.e. not only intermediate "local"
results) otherwise it would end up regenerating the beginning of the sequence
over and over again.
Obviously, Haskell does remember what had already been generated THROUGH
RECURSION since executing the program with GHCI runs quite smoothly and
responsively.
That Haskell manages to do that is for me "magnifique". But I need to know 
(if
only a little) about how it achieves this in order to know what I, as a
lambda programmer, can do, and how to compute the Big-Oh complexity of the
algorithm.

Thank you,
Francis Girard
FRANCE
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Graham Klyne
For email:
http://www.ninebynine.org/#Contact
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Newbie : How come that cyclic recursive lists are efficient ?

2005-01-24 Thread Lennart Augustsson
It doesn't have to be a top level definition, it works anyway.
-- Lennart
Bruno Abdon wrote:
'hamming', in your code, is a top-level definition. When used three
times inside its own definition, it's the same variable being used
three times. You don't recompute a variable value in order to reuse
it.
As an example, if you do
foo :: [Integer]
foo = [1,2,3] + [4,5]
bar = foo ++ foo  ++ foo
the concatenation used to produce foo will not be done three times in
order to calculate the value of bar. That would be true for any
function would foo be defined upon, not only concatenation.
Bruno Abdon
On Mon, 24 Jan 2005 10:38:35 +0100, Francis Girard
<[EMAIL PROTECTED]> wrote:
Hi,
The classical Hamming problem have the following solution in Haskell :
*** BEGIN SNAP
-- hamming.hs
-- Merges two infinite lists
merge :: (Ord a) => [a] -> [a] -> [a]
merge (x:xs)(y:ys)
 | x == y= x : merge xs ys
 | x <  y= x : merge xs (y:ys)
 | otherwise = y : merge (x:xs) ys
-- Lazily produce the hamming sequence
hamming :: [Integer]
hamming
 = 1 : merge (map (2*) hamming) (merge (map (3*) hamming) (map (5*) hamming))
*** END SNAP
I just love these algorithms that run after their tail (they make my brain
melt) but I don't know how is it that they are efficient.
Here, the hamming recursively calls itself three times. For this algorithm to
be efficient, the Haskell system, somehow, has to "remember" the already
generated sequence THROUGH RECURSION (i.e. not only intermediate "local"
results) otherwise it would end up regenerating the beginning of the sequence
over and over again.
Obviously, Haskell does remember what had already been generated THROUGH
RECURSION since executing the program with GHCI runs quite smoothly and
responsively.
That Haskell manages to do that is for me "magnifique". But I need to know (if
only a little) about how it achieves this in order to know what I, as a
lambda programmer, can do, and how to compute the Big-Oh complexity of the
algorithm.
Thank you,
Francis Girard
FRANCE
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


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


Re: [Haskell] Newbie : How come that cyclic recursive lists are efficient ?

2005-01-24 Thread Bruno Abdon
'hamming', in your code, is a top-level definition. When used three
times inside its own definition, it's the same variable being used
three times. You don't recompute a variable value in order to reuse
it.

As an example, if you do

foo :: [Integer]
foo = [1,2,3] + [4,5]

bar = foo ++ foo  ++ foo

the concatenation used to produce foo will not be done three times in
order to calculate the value of bar. That would be true for any
function would foo be defined upon, not only concatenation.

Bruno Abdon

On Mon, 24 Jan 2005 10:38:35 +0100, Francis Girard
<[EMAIL PROTECTED]> wrote:
> Hi,
> 
> The classical Hamming problem have the following solution in Haskell :
> 
> *** BEGIN SNAP
> -- hamming.hs
> 
> -- Merges two infinite lists
> merge :: (Ord a) => [a] -> [a] -> [a]
> merge (x:xs)(y:ys)
>   | x == y= x : merge xs ys
>   | x <  y= x : merge xs (y:ys)
>   | otherwise = y : merge (x:xs) ys
> 
> -- Lazily produce the hamming sequence
> hamming :: [Integer]
> hamming
>   = 1 : merge (map (2*) hamming) (merge (map (3*) hamming) (map (5*) hamming))
> *** END SNAP
> 
> I just love these algorithms that run after their tail (they make my brain
> melt) but I don't know how is it that they are efficient.
> 
> Here, the hamming recursively calls itself three times. For this algorithm to
> be efficient, the Haskell system, somehow, has to "remember" the already
> generated sequence THROUGH RECURSION (i.e. not only intermediate "local"
> results) otherwise it would end up regenerating the beginning of the sequence
> over and over again.
> 
> Obviously, Haskell does remember what had already been generated THROUGH
> RECURSION since executing the program with GHCI runs quite smoothly and
> responsively.
> 
> That Haskell manages to do that is for me "magnifique". But I need to know (if
> only a little) about how it achieves this in order to know what I, as a
> lambda programmer, can do, and how to compute the Big-Oh complexity of the
> algorithm.
> 
> Thank you,
> 
> Francis Girard
> FRANCE
> 
> ___
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
> 


-- 
Bruno Abdon

Firefox Browser. Take Back the Web
http://www.mozilla.org/products/firefox/

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


[Haskell] Newbie : How come that cyclic recursive lists are efficient ?

2005-01-24 Thread Francis Girard
Hi,

The classical Hamming problem have the following solution in Haskell :

*** BEGIN SNAP
-- hamming.hs

-- Merges two infinite lists
merge :: (Ord a) => [a] -> [a] -> [a]
merge (x:xs)(y:ys)
  | x == y= x : merge xs ys
  | x <  y= x : merge xs (y:ys)
  | otherwise = y : merge (x:xs) ys

-- Lazily produce the hamming sequence
hamming :: [Integer]
hamming 
  = 1 : merge (map (2*) hamming) (merge (map (3*) hamming) (map (5*) hamming))
*** END SNAP

I just love these algorithms that run after their tail (they make my brain 
melt) but I don't know how is it that they are efficient.

Here, the hamming recursively calls itself three times. For this algorithm to 
be efficient, the Haskell system, somehow, has to "remember" the already 
generated sequence THROUGH RECURSION (i.e. not only intermediate "local" 
results) otherwise it would end up regenerating the beginning of the sequence 
over and over again.

Obviously, Haskell does remember what had already been generated THROUGH 
RECURSION since executing the program with GHCI runs quite smoothly and 
responsively.

That Haskell manages to do that is for me "magnifique". But I need to know (if 
only a little) about how it achieves this in order to know what I, as a 
lambda programmer, can do, and how to compute the Big-Oh complexity of the 
algorithm.

Thank you,

Francis Girard
FRANCE

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


Re: [Haskell] Newbie Question about Types

2004-09-06 Thread Graham Klyne
I maybe don't fully grasp your goals here, but this sounds similar to some 
early problems I ran into with Haskell (coming from comparable background), 
and here are a couple of comments that _might_ just help:

(a) adding a type context to a 'data' declaration seems to be very rarely, 
if ever, of any real benefit.  You still have to declare the context on the 
relevant instance functions of the class, and its presence in the data 
declaration adds constraints that still need to be satisfied 
somehow.  Suggest:  simply drop the context from the data declaration and 
add them as-needed to the functions assigned as component values of that 
datatype.

(b) is what you want *really* a Haskell class?  Have you considered 
creating a data type whose methods are the required functions.  Different 
values of that datatype may have different component functions.  E.g.

data Fooable a =
 { foo1 :: a -> a -> a
 , foo2 :: a -> a -> a
 }
#g
--
At 14:57 27/08/04 -0400, David Greenberg wrote:
Hi,
I very recently just came to Haskell from the Java and Perl worlds, so
my understanding of Haskell's type system is still a little vague.
The tutorial and Google didn't seem to have an answer to my question,
so I am hoping someone here might be able to help me.  I am writing
some code comparable to the following:
class Fooable a where
 foo1 :: a -> a -> a
 foo2 :: a -> a -> a
type MyType a = String -> a
data (Fooable (MyType a)) => AnotherType a =
 AnotherType {str :: String, myval :: (MyType a)}
instance (Fooable (MyType a)) => Fooable (AnotherType a) where
 (AnotherType s1 m1) `foo1` (AnotherType s2 m2) =
  AnotherType "dummy string" (m1 `foo1` m2)
The trick here is I want to be able to pass a value of type MyType to
the AnotherType constructor without making MyType directly an instance
of Fooable.  In other words, I want some sort of sub-type of MyType to
be an instance of Fooable.  That way I can use it in the constructor
of AnotherType.
I understand that type inference might make a lot of this easier, but
I am trying to make a very strict API out of my module(s), and feel
that relying on inference at this stage could become buggy.
Thanks in advance for any help that you all can give me.
-David
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Graham Klyne
For email:
http://www.ninebynine.org/#Contact
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] Newbie Question about Types

2004-08-27 Thread David Greenberg
Hi,

I very recently just came to Haskell from the Java and Perl worlds, so
my understanding of Haskell's type system is still a little vague. 
The tutorial and Google didn't seem to have an answer to my question,
so I am hoping someone here might be able to help me.  I am writing
some code comparable to the following:

class Fooable a where
 foo1 :: a -> a -> a
 foo2 :: a -> a -> a

type MyType a = String -> a

data (Fooable (MyType a)) => AnotherType a = 
 AnotherType {str :: String, myval :: (MyType a)}
instance (Fooable (MyType a)) => Fooable (AnotherType a) where
 (AnotherType s1 m1) `foo1` (AnotherType s2 m2) = 
  AnotherType "dummy string" (m1 `foo1` m2)

The trick here is I want to be able to pass a value of type MyType to
the AnotherType constructor without making MyType directly an instance
of Fooable.  In other words, I want some sort of sub-type of MyType to
be an instance of Fooable.  That way I can use it in the constructor
of AnotherType.

I understand that type inference might make a lot of this easier, but
I am trying to make a very strict API out of my module(s), and feel
that relying on inference at this stage could become buggy.

Thanks in advance for any help that you all can give me.

-David
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] newbie question: variable not in scope: "isSpace"

2004-08-14 Thread Tom Pledger
A.J. Bonnema wrote:
If I use isSpace from the hugs interpretor, it works.
If I use isSpace from a test.hs file I get the error message:
Undefined variable "isSpace"
From ghc I get the error message:
Variable not in scope: "isSpace"
What is wrong? 

Hugs automatically imports a few extra things as well as the standard 
prelude. Try adding the line

   import Data.Char
to your module.
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] newbie question: variable not in scope: "isSpace"

2004-08-14 Thread A.J. Bonnema
If I use isSpace from the hugs interpretor, it works.
If I use isSpace from a test.hs file I get the error message:
Undefined variable "isSpace"
From ghc I get the error message:
Variable not in scope: "isSpace"
What is wrong?
Guus.
--
A.J. Bonnema, Leiden The Netherlands,
user #328198 (Linux Counter http://counter.li.org)
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] newbie question

2004-02-09 Thread Lee Render
is "HaskellScript" still working?
I tried mucking around with this lately using the
latest version of Hugs but the example scripts seemed
broken.


__
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Haskell help for Haskell newbie.

1995-06-26 Thread Alain M. Gaudrault


I've only recently started dabbling in Haskell, and functional
programming in general, and am having a few problems, one particular to
Haskell as a functional language, the other with Haskell's type classes.  Just
in case it matters, I'm using "interactive Haskell B. version 0.999.7 SPARC
1994 Oct 17".  Let's start with the simpler problem:

1) let fred x = x in fred fred;

Haskell complains:
[55] Ambiguously overloaded tyvar(s) in class(es) Text in  show (let {
fred = \A1_fred -> A1_fred
} in fred fred)

while the equivalent ML statement (let fun fred x = x in fred fred end;)
returns a function of type ('a -> 'a) or simply (a -> a) in Haskell-speak.
Why can I not generate this definition?


2) I'm attempting to add another instance to the Num class as a test of
Haskell's OOP functionality.  Thus, I create a new type which is a 3-tuple:

data ThreeSpace = TS (Integer, Integer, Integer);

Then, for each of the methods required by Num, a function is defined for the
new type.  Warning, I don't know what 'signum' should do, so I return its
input.

let addTS (TS (x1, x2, x3)) (TS (y1, y2, y3)) = TS ((x1+y1), (x2+y2), (x3+y3));;
let subTS (TS (x1, x2, x3)) (TS (y1, y2, y3)) = TS ((x1-y1), (x2-y2), (x3-y3));;
let mulTS (TS (x1, x2, x3)) (TS (y1, y2, y3)) = TS ((x1*y1), (x2*y2), (x3*y3));;
let negTS (TS (x1, x2, x3)) = TS ((x1-x1-x1), (x2-x2-x2), (x3-x3-x3));;
let absTS (TS (x1, x2, x3)) = TS ((abs x1), (abs x2), (abs x3));;
let signumTS (TS (x1, x2, x3)) = TS (x1, x2, x3);;
let fIntegerTS x = TS ((fromInteger x), 0, 0);;
let fIntTS :: Int -> ThreeSpace; fIntTS x = TS ((fromInt x), 0, 0);;

Now, I need to add the ThreeSpace instance to Num:

instance Num ThreeSpace where
(+) = addTS
(-) = subTS
(*) = mulTS
negate = negTS
abs = absTS
signum = signumTS
fromInteger = fIntegerTS
fromInt = fIntTS
;

This is where things crap out.  I get the following error:

[56] Not an instance Num ThreeSpace in  ((DD.Num.$fromInteger{FARITY 1}))::(Integer, 
Int, Double) -> ThreeSpace
 in $fromInteger

I haven't the faintest clue what this error message means, particularly the
"(Integer, Int, Double) -> ThreeSpace" which looks like a function which takes
a 3-tuple and returns a 'ThreeSpace'.  "whatis fromInteger" tells me:

method PreludeCore.fromInteger :: (Num a) => Integer -> a

so I know my definition typechecks.  I've tried everything I could think of to
get this going, but to no avail.  Help!

No light at the end of the tunnel,
  Big Al the Devil's Pal!!
 __   __
/  `-' /  ,,
|[|||[::}
\__.-._\  ``