[Haskell-cafe] First steps in Haskell

2005-12-18 Thread Daniel Carrera

Hello all,

I'm trying to write the simplest possible Haskell program, and I'm not 
getting anywhere.


I have installed Hugs, GHC and GHCI. I want to run the following program:

fac :: Integer -> Integer
fac 0 = 1
fac n | n > 0 = n * fac (n-1)

This is what I see:

$ hugs
Hugs.Base> fac :: Integer -> Integer
ERROR - Undefined variable "fac"
Hugs.Base> fac 0 = 1
ERROR - Syntax error in input (unexpected `=')


$ ghci
Prelude> fac :: Integer -> Integer

:1:0: Not in scope: `fac'
Prelude> fac 0 = 1
:1:6: parse error on input `='

$ # Write the program to fac.hs
$ ghc fac.hs

fac.hs:1:0:
The main function `main' is not defined in module `Main'
When checking the type of the main function `main'



This is a real problem for Haskell. I expect that a lot of people try 
Haskell and give up because they can't even write the simplest function. 
It's hard not to be put off by this. I love the theory behind Haskell, 
but the practice of it seems to be a real problem.


I hope someone will show me how to make this program work. Even better, 
I hope someone will fix the compilers and interpreters if they need 
fixing, or fix the documentation if that's what needs fixing.


Best,
Daniel.
--
 /\/`) http://oooauthors.org
/\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/I am not over-weight, I am under-tall.
   /
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] First steps in Haskell

2005-12-18 Thread Lemmih
On 12/18/05, Daniel Carrera <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I'm trying to write the simplest possible Haskell program, and I'm not
> getting anywhere.
>
> I have installed Hugs, GHC and GHCI. I want to run the following program:
>
> fac :: Integer -> Integer
> fac 0 = 1
> fac n | n > 0 = n * fac (n-1)
>
> This is what I see:
>
> $ hugs
> Hugs.Base> fac :: Integer -> Integer
> ERROR - Undefined variable "fac"
> Hugs.Base> fac 0 = 1
> ERROR - Syntax error in input (unexpected `=')
>
>
> $ ghci
> Prelude> fac :: Integer -> Integer
>
> :1:0: Not in scope: `fac'
> Prelude> fac 0 = 1
> :1:6: parse error on input `='
>
> $ # Write the program to fac.hs
> $ ghc fac.hs
>
> fac.hs:1:0:
>  The main function `main' is not defined in module `Main'
>  When checking the type of the main function `main'

GHC is a compiler. If you want to compile to a binary then you must
define a function called 'main'. Otherwise just load the file in ghci
(`ghci fac.hs`).

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


Re: [Haskell-cafe] First steps in Haskell

2005-12-18 Thread Joel Koerwer
Try ghci fac.hs. You will then have an interactive session with access to the definitions in your file.Then after you've played with you creation a bit, check out http://haskell.org/learning.html
Welcome and enjoy!Joel
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] First steps in Haskell

2005-12-18 Thread Chris Kuklewicz
Daniel Carrera wrote:

>> Hello all,
>>
>> I'm trying to write the simplest possible Haskell program, and I'm not
>> getting anywhere.
>>
>> I have installed Hugs, GHC and GHCI. I want to run the following program:
>>
>> fac :: Integer -> Integer
>> fac 0 = 1
>> fac n | n > 0 = n * fac (n-1)
>>


$ ghci

Prelude> let { fac :: Integer -> Integer; fac 0 = 1; fac n | n > 0 = n *
fac (n-1) }
Prelude> fac 12
479001600




>>
>> This is a real problem for Haskell. I expect that a lot of people try
>> Haskell and give up because they can't even write the simplest function.
>> It's hard not to be put off by this. I love the theory behind Haskell,
>> but the practice of it seems to be a real problem.
>>
>> I hope someone will show me how to make this program work. Even better,
>> I hope someone will fix the compilers and interpreters if they need
>> fixing, or fix the documentation if that's what needs fixing.
>>
>> Best,
>> Daniel.


Almost everything is explained under

http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ghci.html

The main things is: The ghci prompt accepts either command, starting with
a color such as :load
"filename" or haskell IO code, since it is in a do-block. Thus let is
required.

The 2-D Layout syntax does not work at the ghci prompt, thus the
braces-and-semicolon style I used.

More typically you would write your code in a file, as shown in:
http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ch03s02.html


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


Re: [Haskell-cafe] First steps in Haskell

2005-12-18 Thread Daniel Carrera

Lemmih wrote:

GHC is a compiler. If you want to compile to a binary then you must
define a function called 'main'. Otherwise just load the file in ghci
(`ghci fac.hs`).


I would expect GHC to be able to compile a program with a function that 
is not called 'main'. I wouldn't expect it to print anything when run, 
but I would expect it to compile.


`ghci fac.hs` doesn't give any errors. I don't understand why loading 
the file like that is ok but typing the entries is not. This might be a 
problem for people exporing the language.


Best,
Daniel.
--
 /\/`) http://oooauthors.org
/\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/I am not over-weight, I am under-tall.
   /
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] First steps in Haskell

2005-12-18 Thread Daniel Carrera

Chris Kuklewicz wrote:

Almost everything is explained under

http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ghci.html


Ok. How would a visitor to the Haskell site find this document? If this 
is the correct document for a beginner to start with Haskell, perhaps 
the site should be updated to point to it instead of the documents it 
currently points to.


I find some usability problems in the documentation section. Think of 
usability in terms of barriers. If you have low barriers, a lot of 
people will have enough motivation to cross them and get started with 
Haskell. If the barriers are very high, only the most intent and 
motivated users will get started. Barriers are bad.


Consider some barriers for a user who wants to learn Haskell:

* There's no way for a new user to figure out how to successfully run 
the simplest Haskell program.
* The first tutorial listed requires the user to give up some personal 
information before getting the tutorial.


These are very significant barriers.

Sure, it's not all bad. For example, Haskell has a friendly community 
(low barrier). But the barriers that exist are a problem because they 
hit the person who is trying to take the very very first step. If you 
can make that *fist* step easier, more people will take it.



The main things is: The ghci prompt accepts either command, starting
with a color such as :load "filename" or haskell IO code, since it
is in a do-block. Thus let is required.


I understand that the design of Haskell might force this behaviour (I 
don't know, but I guess it must). The best solution I can think of (from 
a usability POV) is to provide a very brief tutorial, just 1/2 page, 
just enough to get someone through "hello world", and put it right at 
the top of the Learning Haskell section. I would remove the Intro 
section (it would fit better on the front page) and replace it with a 
1/2 page tutorial. Something like this:


-// Sugestion -
40-SECOND INTRO TO HASKELL

(You must have Hugs or GHC installed)

1. Open a text editor and type:
fac :: Integer -> Integer
fac 0 = 1
fac n | n > 0 = n * fac (n-1)

2. Save as "fac.hs"
3. On a terminal:

$ ghci
Prelude> :load fac.hs
Compiling Main ( fac.hs, interpreted )
Ok, modules loaded: Main.
*Main> fac 12
479001600

4. Press Ctrl+D to exit.

For more information, look at the following tutorials:
-// Sugestion -

There. That's brief, and it's enough to get the user past the first 
step. It sends the message that Haskell is not so scary.




More typically you would write your code in a file, as shown in:
http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ch03s02.html


Thanks.

Best,
Daniel.
--
 /\/`) http://oooauthors.org
/\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/I am not over-weight, I am under-tall.
   /
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] First steps in Haskell

2005-12-18 Thread Daniel Carrera

Joel Koerwer wrote:
Then after you've played with you creation a bit, check out 
http://haskell.org/learning.html 


Thank you. I did find that page, and it was very easy to find. The 
problem is that the content of that page, and its links, didn't show me 
how to write a Haskell program (like you did).


Best,
Daniel.
--
 /\/`) http://oooauthors.org
/\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/I am not over-weight, I am under-tall.
   /
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] First steps in Haskell

2005-12-18 Thread Sebastian Sylvan
On 12/18/05, Daniel Carrera <[EMAIL PROTECTED]> wrote:
> Lemmih wrote:
> > GHC is a compiler. If you want to compile to a binary then you must
> > define a function called 'main'. Otherwise just load the file in ghci
> > (`ghci fac.hs`).
>
> I would expect GHC to be able to compile a program with a function that
> is not called 'main'. I wouldn't expect it to print anything when run,
> but I would expect it to compile.

It can. To compile a module use the "-c" ('c' for "compile"). If you
want an executable you will need to have an entry-point (which is
main).

Typically you would write your program in a file, have a main
function, and then write

ghc --make MyMainModule.hs -o MyExecutableName

Optionally adding "-O" or "-O2" for optimisation.

The "--make" flag is really useful as it will cause GHC to track down
dependencies automatically and compile them if needed (reducing the
need for makefiles etc.).

/S

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


Re: [Haskell-cafe] First steps in Haskell

2005-12-18 Thread Cale Gibbard
The ordinary usage pattern, which I recall is actually described in a
number of the tutorials, and on the wiki, probably in a number of
places, is to write your program text into a file with an editor, and
then load it at a terminal with either ghci fac.hs or hugs fac.hs.
(See http://www.haskell.org/hawiki/HaskellNewbie/HaskellInterpreterUsage,
as that's a conglomeration of a few of the question/answers that were
scattered about)

At that point, you can evaluate *expressions* at the ghci/hugs prompt,
to observe the operation of your program (think of it like a
debugger). This is different from entering declarations in that you
can't define things. GHCi specifically allows function/value
declarations with let (as it is somewhat emulating the inside of a
do-block), but it won't allow other kinds (data declarations, etc.).
"let x = 5 in x * x" works in either one, as it is an expression.

Note that you can type :r at the ghci or hugs prompt to reload your
file whenever you save it in your editor, so it's fairly easy to keep
things in sync.

If you want to compile your program with ghc proper, you'll need a
main action. Otherwise, well, what would the produced binary do? A
simple main is provided by printing some value, so I could add to your
program

main = print (fac 1000)

and then compile it, and the binary produced would print the integer
value of 1000! to the terminal.

Note that the interactive environments would have a hard time loading
ad-hoc Haskell code on stdin, as there may be, for instance, mutually
recursive bindings, and data types used in one function might be
declared later in the file. (Thus, testing that function would result
in an error message which currently isn't possible, a run-time type
error.) Further, the layout rule complicates the issue as to whether a
given line was intended as an expression, or the first part of a
declaration. I think it would be more confusing than what we currently
have.

Hope this helps,
 - Cale

On 18/12/05, Daniel Carrera <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I'm trying to write the simplest possible Haskell program, and I'm not
> getting anywhere.
>
> I have installed Hugs, GHC and GHCI. I want to run the following program:
>
> fac :: Integer -> Integer
> fac 0 = 1
> fac n | n > 0 = n * fac (n-1)
>
> This is what I see:
>
> $ hugs
> Hugs.Base> fac :: Integer -> Integer
> ERROR - Undefined variable "fac"
> Hugs.Base> fac 0 = 1
> ERROR - Syntax error in input (unexpected `=')
>
>
> $ ghci
> Prelude> fac :: Integer -> Integer
>
> :1:0: Not in scope: `fac'
> Prelude> fac 0 = 1
> :1:6: parse error on input `='
>
> $ # Write the program to fac.hs
> $ ghc fac.hs
>
> fac.hs:1:0:
>  The main function `main' is not defined in module `Main'
>  When checking the type of the main function `main'
>
>
>
> This is a real problem for Haskell. I expect that a lot of people try
> Haskell and give up because they can't even write the simplest function.
> It's hard not to be put off by this. I love the theory behind Haskell,
> but the practice of it seems to be a real problem.
>
> I hope someone will show me how to make this program work. Even better,
> I hope someone will fix the compilers and interpreters if they need
> fixing, or fix the documentation if that's what needs fixing.
>
> Best,
> Daniel.
> --
>   /\/`) http://oooauthors.org
>  /\/_/  http://opendocumentfellowship.org
> /\/_/
> \/_/I am not over-weight, I am under-tall.
> /
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] First steps in Haskell

2005-12-18 Thread Cale Gibbard
On 18/12/05, Daniel Carrera <[EMAIL PROTECTED]> wrote:
> Chris Kuklewicz wrote:
> > Almost everything is explained under
> >
> > http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ghci.html
>
> Ok. How would a visitor to the Haskell site find this document? If this
> is the correct document for a beginner to start with Haskell, perhaps
> the site should be updated to point to it instead of the documents it
> currently points to.
>
> I find some usability problems in the documentation section. Think of
> usability in terms of barriers. If you have low barriers, a lot of
> people will have enough motivation to cross them and get started with
> Haskell. If the barriers are very high, only the most intent and
> motivated users will get started. Barriers are bad.
>
> Consider some barriers for a user who wants to learn Haskell:
>
> * There's no way for a new user to figure out how to successfully run
> the simplest Haskell program.
> * The first tutorial listed requires the user to give up some personal
> information before getting the tutorial.

Google for "Yet Another Haskell Tutorial pdf", and you'll find that
this form can be subverted if you actually care. It also accepts
completely random values.

>
> These are very significant barriers.
>
> Sure, it's not all bad. For example, Haskell has a friendly community
> (low barrier). But the barriers that exist are a problem because they
> hit the person who is trying to take the very very first step. If you
> can make that *fist* step easier, more people will take it.
>
> > The main things is: The ghci prompt accepts either command, starting
> > with a color such as :load "filename" or haskell IO code, since it
> > is in a do-block. Thus let is required.
>
> I understand that the design of Haskell might force this behaviour (I
> don't know, but I guess it must). The best solution I can think of (from
> a usability POV) is to provide a very brief tutorial, just 1/2 page,
> just enough to get someone through "hello world", and put it right at
> the top of the Learning Haskell section. I would remove the Intro
> section (it would fit better on the front page) and replace it with a
> 1/2 page tutorial. Something like this:
>
> -// Sugestion -
> 40-SECOND INTRO TO HASKELL
>
> (You must have Hugs or GHC installed)
>
> 1. Open a text editor and type:
> fac :: Integer -> Integer
> fac 0 = 1
> fac n | n > 0 = n * fac (n-1)
>
> 2. Save as "fac.hs"
> 3. On a terminal:
>
> $ ghci
> Prelude> :load fac.hs
> Compiling Main ( fac.hs, interpreted )
> Ok, modules loaded: Main.
> *Main> fac 12
> 479001600
>
> 4. Press Ctrl+D to exit.
>
> For more information, look at the following tutorials:
> -// Sugestion -
>
> There. That's brief, and it's enough to get the user past the first
> step. It sends the message that Haskell is not so scary.
>
>
> > More typically you would write your code in a file, as shown in:
> > http://www.haskell.org/ghc/docs/6.4.1/html/users_guide/ch03s02.html
>
> Thanks.
>
> Best,
> Daniel.
> --
>   /\/`) http://oooauthors.org
>  /\/_/  http://opendocumentfellowship.org
> /\/_/
> \/_/I am not over-weight, I am under-tall.
> /
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: Re[2]: [Haskell-cafe] Substring replacements

2005-12-18 Thread Branimir Maksimovic





From: Bulat Ziganshin <[EMAIL PROTECTED]>
Reply-To: Bulat Ziganshin <[EMAIL PROTECTED]>
To: "Branimir Maksimovic" <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED], Haskell-Cafe@haskell.org
Subject: Re[2]: [Haskell-cafe] Substring replacements
Date: Fri, 16 Dec 2005 16:51:32 +0300

Hello Branimir,

Friday, December 16, 2005, 5:36:47 AM, you wrote:
BM> I've also performed tests on dual Xeon linux box and results are

just to let you know - GHC don't uses pentium4 hyperthreading,
multiple cpus or multiple cores in these tests

only way to make ghc using multiple processors is to use 6.5 beta
version, compile with "-smp" and explicitly fork several threads



You are right. I've double checked on linux there is just one thread
executing and there is not such a big difference between KMP and
straightforward search.
Just about 10% KMP is faster with my test, but still faster.
I've checked both SMP and non SMP linux (Intel).
Hyperthreading effect is on windows only, I guess, as there
are visible three threads per test process.
I have one amd64 near (I'll check that one too, as soon as admin
sets up account for me on that machine).

Greetings, Bane.

_
Don't just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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


[Haskell-cafe] About print and side-effects

2005-12-18 Thread Daniel Carrera

Hi all,

The recent responses to my first question (thanks guys!) included the 
following bit:


main = print (fact 42)


Now, print is a side-effect. Shouldn't it involve a do-block or a nomad 
or one of those scary things you hear about when learning about side 
effects in functional programs? How come 'print' is allowed to exist 
alone if it's a side-effect?


Thanks for the help.

Cheers,
Daniel.
--
 /\/`) http://oooauthors.org
/\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/I am not over-weight, I am under-tall.
   /
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About print and side-effects

2005-12-18 Thread Anders Höckersten
sön 2005-12-18 klockan 20:22 + skrev Daniel Carrera:
> Hi all,
> 
> The recent responses to my first question (thanks guys!) included the 
> following bit:
> 
> main = print (fact 42)
> 
> 
> Now, print is a side-effect. Shouldn't it involve a do-block or a nomad 
> or one of those scary things you hear about when learning about side 
> effects in functional programs? How come 'print' is allowed to exist 
> alone if it's a side-effect?
> 
> Thanks for the help.
> 
> Cheers,
> Daniel.

Daniel, first of all I would like to invite you to #haskell on
irc.freenode.net. There are almost always people there to answer quick
questions like this one, with less of the waiting period that's involved
in a mailing list. You are of course also welcome to continue asking
your questions here if you prefer.

To answer your question: Yes, your main function does in fact involve
the IO monad. You can easily check the type of main or any function you
write by typing for example ":t main" in GHCi or Hugs. If you do this,
you will see that main has the type signature "main :: IO ()". The
reason you don't need do-blocks for this particular function is because
it only involves one computation. If you have more than one, you need
do-notation (well, there's a more correct and longer explanation for all
this, but we can save that one for later).

Oh, and don't mistake monads for scary things, they are really quite
warm and fuzzy once you get to know them. :)

Regards,
Anders


signature.asc
Description: Detta är en digitalt signerad	meddelandedel
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About print and side-effects

2005-12-18 Thread Chris Kuklewicz

Daniel Carrera wrote:
> Hi all,
> 
> The recent responses to my first question (thanks guys!) included the
> following bit:
> 
> main = print (fact 42)

You can use a "do" block:

main = do
  print (fact 42)

which also works.

But for a single thing of type (IO _) the "do" is optional.

> 
> 
> Now, print is a side-effect. Shouldn't it involve a do-block or a nomad
> or one of those scary things you hear about when learning about side
> effects in functional programs? How come 'print' is allowed to exist
> alone if it's a side-effect?
> 
> Thanks for the help.
> 
> Cheers,
> Daniel.

By nomad you seemed to either be ridiculing or misspelling monad. The
right-hand-side of main must have type "IO _" where _ is whatever type
you program returns, often "()".  The print command has type "print ::
forall a. (Show a) => a -> IO ()" so the type of "print (fac 42)" is the
desired type "IO ()".  Thus there is no need for special "do" syntax or
monad operators >> or >>=.

Lets say you want to print several values:

main = do putStr "(fact 42) is "
  print (fact 42)
  putStr "(fact 1) is "
  print (fact 1)

That is the do-syntax with the whitespace sensitive 2D layout syntax.

This is equivalent to

main = do { putStr "(fac 42) is ";  print (fact 42);
 putStr "(fac 1) is "; print (fact 1); }

Now do-syntax is just sugar for (slighty simplified here):

main = putStr "(fac 42) is " >>  print (fact 42) >>
   putStr "(fac 1) is "">> print (fact 1)

Where >> is an infix, binary operator that takes commands and returns
the concatenated command.  So the above is a single action that is the
concatenation of the four IO commands.

Since it is now a single command, no "do" is needed.

The value of the whitespace form is that some people are happier reading
and writing it.  The value of the {;} syntax is that it is very familiar
and perhaps more pleasing to some people and perhaps more pleasing to
some code generaion tools.  The value of the de-sugared form is that it
*is* the Monadic form (which acutally uses >>= and case statements,
details in the language definition
http://www.informatik.uni-freiburg.de/~thiemann/haskell/haskell98-report-html/exps.html#sect3.14
)

Sometime the Monadic form can be used to remove unhelpful variable
bindings that clutter code.  This can lead to clearer code.

Note that the whitespace layout form has much less punctuation, and only
a single two letter keyword.  Unlike python the decision about how much
to indent is up to the author, but the command must be lined up.

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


Re: [Haskell-cafe] About print and side-effects

2005-12-18 Thread Daniel Carrera

Chris Kuklewicz wrote:

By nomad you seemed to either be ridiculing or misspelling monad.


Misspelling. It's a new word for me. I'm not really sure what it means. 
I expect it'll take me a while to figure it out.


Thank you for the help.

Best,
Daniel.
--
 /\/`) http://oooauthors.org
/\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/I am not over-weight, I am under-tall.
   /
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] About print and side-effects

2005-12-18 Thread Sebastian Sylvan
On 12/18/05, Daniel Carrera <[EMAIL PROTECTED]> wrote:
> Chris Kuklewicz wrote:
> > By nomad you seemed to either be ridiculing or misspelling monad.
>
> Misspelling. It's a new word for me. I'm not really sure what it means.
> I expect it'll take me a while to figure it out.

It sounds scary, I know!
For now I'd recommend you to just think of it as "A computation, which
may have side-effects, returning a value". And consider the
do-notation as a way to "merge multiple computations together into a
single one".
For instance, "print" is a computation taking a showable value,
returning () with the side effect that a string representation of the
value is printed to stdout.

Writing an IO program is then easily conceptualised as just "merging"
together several existing IO computations into a single one. The
compiler will take care of generating code for actually *running* the
IO computation, your job is to define it.

Monads have more uses than this, and there's a bit of interesting
things to think about when learning about them, but you should
probably hold off on that for now.

/S

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


[Haskell-cafe] Int vs Integer

2005-12-18 Thread Daniel Carrera

Hello all,

I found a good Haskell tutorial (second link on the Tutorials column) 
(now that I know how to run the programs in it). I have a question. 
What's the difference between the types Int and Integer? Likewise, 
what's the difference between the types Float and Double? Are those just 
synonims?


Thanks for the help.

Cheers,
Daniel.
--
 /\/`) http://oooauthors.org
/\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/I am not over-weight, I am under-tall.
   /
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Int vs Integer

2005-12-18 Thread Chris Kuklewicz
Daniel Carrera wrote:
> Hello all,
>
> I found a good Haskell tutorial (second link on the Tutorials column)
> (now that I know how to run the programs in it). I have a question.
> What's the difference between the types Int and Integer? Likewise,
> what's the difference between the types Float and Double? Are those just
> synonims?

Ah, that question is about core language types.

The relevant section from the Haskell 98 Language Report (revised 2002):

http://www.haskell.org/onlinereport/basic.html#sect6.4

The report, top link: http://www.haskell.org/onlinereport/
Though the report is not the best tutorial for some things.

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


Re: [Haskell-cafe] Int vs Integer

2005-12-18 Thread Jared Updike
Int is for bounded values -2**32 to 2**32 (I think... maybe 2**-31 and
2**31 or less if it's boxed?) based on the underlying machine
representation. Integer is unbounded (arbitrary precision, i.e.
7489571948579148758174534 is a valid Integer). Double is for floating
point values corresponding to C doubles, in hardware (on 32 bit
machines, 64 bit entities) and Floats are half that precision, i.e. 32
bits on 32 bit machines, corresponding to C floats.

see  http://www.haskell.org/onlinereport/basic.html#sect6.3 and
http://www.haskell.org/onlinereport/basic.html#sect6.4 for more info.

 Jared.

On 12/18/05, Daniel Carrera <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I found a good Haskell tutorial (second link on the Tutorials column)
> (now that I know how to run the programs in it). I have a question.
> What's the difference between the types Int and Integer? Likewise,
> what's the difference between the types Float and Double? Are those just
> synonims?
>
> Thanks for the help.
>
> Cheers,
> Daniel.
> --
>   /\/`) http://oooauthors.org
>  /\/_/  http://opendocumentfellowship.org
> /\/_/
> \/_/I am not over-weight, I am under-tall.
> /
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


--
[EMAIL PROTECTED]
http://www.updike.org/~jared/
reverse ")-:"
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Int vs Integer

2005-12-18 Thread Daniel Carrera

Thanks for the info, and the link.

I probably should have guessed the Double vs Float one. I did program in 
C a while ago...


Cheers,
Daniel.

Jared Updike wrote:

Int is for bounded values -2**32 to 2**32 (I think... maybe 2**-31 and
2**31 or less if it's boxed?) based on the underlying machine
representation. Integer is unbounded (arbitrary precision, i.e.
7489571948579148758174534 is a valid Integer). Double is for floating
point values corresponding to C doubles, in hardware (on 32 bit
machines, 64 bit entities) and Floats are half that precision, i.e. 32
bits on 32 bit machines, corresponding to C floats.

see  http://www.haskell.org/onlinereport/basic.html#sect6.3 and
http://www.haskell.org/onlinereport/basic.html#sect6.4 for more info.

 Jared.

On 12/18/05, Daniel Carrera <[EMAIL PROTECTED]> wrote:


Hello all,

I found a good Haskell tutorial (second link on the Tutorials column)
(now that I know how to run the programs in it). I have a question.
What's the difference between the types Int and Integer? Likewise,
what's the difference between the types Float and Double? Are those just
synonims?

Thanks for the help.

Cheers,
Daniel.
--
 /\/`) http://oooauthors.org
/\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/I am not over-weight, I am under-tall.
   /
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe





--
[EMAIL PROTECTED]
http://www.updike.org/~jared/
reverse ")-:"
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




--
 /\/`) http://oooauthors.org
/\/_/  http://opendocumentfellowship.org
   /\/_/
   \/_/I am not over-weight, I am under-tall.
   /
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] c2hs seems to ignore the types I give it when generating foreign import declarations

2005-12-18 Thread Manuel M T Chakravarty
Benjamin Franksen:
> On Monday 12 December 2005 02:17, Manuel M T Chakravarty wrote:
> > The darcs version of c2hs
> >
> >   darcs get --partial http://www.cse.unsw.edu.au/~chak/repos/c2hs/
> >
> > now permits the use of a `nocode' keyword ...
> 
> Hello
> 
> not directly related, but are there any plans to add the (still?) 
> missing 'enum define' hooks in teh near future?

This feature is still on the todo list, but it's hard to say when I'll
get around to implementing it.  One reason why enum define is not so
high on the top of the list is that there is a simple workaround.  Here
is an example:

-=- myheader.h -=-
/* A #define enum
 */
#define THIS 1
#define THAT 2

-=- MyBinding.chs -=-
import C2HS

#c
enum ThisThat {
  This = THIS,
  That = THAT
};
#endc
{#enum ThisThat {}#}

In other words, you can use inline C in .chs files to define a C enum
that an enum hook can process.  This is not that much more verbose as
what you would have to write in an enum define hook anyway (as you need
to enumerate all macro names that contribute to the enum anyway).

Moreover, I am always grateful for patches that improve c2hs.

Cheers,
Manuel


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


[Haskell-cafe] Using MonadError within other Monads

2005-12-18 Thread Karl Grapone
Hi,

I'm having trouble making use of MonadError within another Monad, in
this case IO.
I've blundered around for a while, trying various combinations of
things, but I don't think I've fully cottoned-on to nesting of monads.

Following is some code which does not compile, but hopefully shows you
what my intentions are.  I'd appreciate it if someone could show me
how to use the nested monads in this situation.
Thanks.


module Test where

import Control.Monad.Error
import Data.Char
import System.IO


instance Error Int where
noMsg = 1
strMsg = length


f :: IO (Either String String)
f = do
n <- readLn
if n == 2
then
return $ throwError "I don't like strings with 2 characters."
else do
s <- mapErrs2 (g n)
putStrLn s

g :: Int -> IO (Either String  String)
g 0 = throwError "I won't do zero length strings."
g 1 = do
c <- getChar
c' <- mapErrs (h c)
return [c']
g n = do
c <- getChar
cs <- g (n-1)
c' <- mapErrs (h c)
return (c':cs)


h :: Char -> Either Int Char
h c
| isUpper c = throwError 200
| otherwise = return $ toUpper c



mapErrs :: Either Int Char -> Either String Char
mapErrs (Right c) = Right c
mapErrs (Left 200) = Left "The String contained uppercase characters."
mapErrs (Left i) = Left ("Unrecognised failure in h, code = " ++ (show i))

mapErrs2 :: Either String String -> Either String String
mapErrs2 (Right s) = Right s
mapErrs2 (Left e) = Left ("g Error: " ++ e)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Using MonadError within other Monads

2005-12-18 Thread Andrew Pimlott
[It is best to post questions only to haskell-cafe.]

On Mon, Dec 19, 2005 at 03:53:53PM +1300, Karl Grapone wrote:
> I'm having trouble making use of MonadError within another Monad, in
> this case IO.
> I've blundered around for a while, trying various combinations of
> things, but I don't think I've fully cottoned-on to nesting of monads.

Looking at the signature of f,

> f :: IO (Either String String)

"Either String String" is just an ordinary value produced in the IO
monad--the monad structure of IO and "Either String" are completely
independent.  With that in mind, here is a way to make part of your code
type-check:

g n = do
c <- getChar
cs <- g (n-1)
return $ do c' <- mapErrs (h c)
cs' <- cs
return (c':cs')

The outer do is a computation in the IO monad, the inner do is a
computation in the "Either String" monad, and the net effect is an IO
computation returning an "Either String" computation--which is just what
the type signature says.  I had to change your code in 3 other places to
make it type-check; hopefully you can now find them. ;-)

When people speak of nesting monads, they often mean using monad
transformers.  If you were using the ErrorT monad transformers, your
signature would look like

f :: ErrorT String IO String

You might want to try rewriting your code that way, but I would suggest
making it work with the current type signatures first.

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