Send Beginners mailing list submissions to
        beginners@haskell.org

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

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

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


Today's Topics:

   1. Re:  infix and bind pseudonym (Magnus Therning)
   2. Re:  infix and bind pseudonym (Daniel Fischer)
   3.  Re: let indenting problems (7stud)
   4.  Re: let indenting problems (7stud)
   5.  Top beginner mistakes (7stud)
   6.  Basic experimenting with monads (Patrick LeBoutillier)
   7. Re:  Basic experimenting with monads (Conrad Meyer)
   8. Re:  Basic experimenting with monads (Alexander Dunlap)
   9.  Re: Top beginner mistakes (Benjamin L.Russell)
  10.  Re: Top beginner mistakes (7stud)


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

Message: 1
Date: Wed, 4 Mar 2009 14:19:36 +0000
From: Magnus Therning <mag...@therning.org>
Subject: Re: [Haskell-beginners] infix and bind pseudonym
To: Daniel Fischer <daniel.is.fisc...@web.de>
Cc: beginners@haskell.org, Michael Easter <codeto...@gmail.com>
Message-ID:
        <e040b520903040619v49a52da2ie091d1f191853...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Wed, Mar 4, 2009 at 1:20 PM, Daniel Fischer <daniel.is.fisc...@web.de> wrote:
> Am Mittwoch, 4. März 2009 13:59 schrieb Magnus Therning:
>> Yes, there are certain function names that allow infix usage without
>> the back-ticks, the name 'chain' doesn't.  What those function names
>> are?  Roughly you can say that functions that they are functions that
>> look like binary operations, like + - ++ >>> etc.  I'm not sure I read
>> the pangauage spec correctly, but it looks like operators are made up
>> of the following characters !...@#$%^&*+-./\|<=>?~ (IIRC ':' has a
>> special meaning in that it's allowed in "constructors", cf 1:2:[]).
>
> ':' is the symbol-equivalent of an upper case letter, so it's special only if
> it's the first symbol of an operator name, then the operator is a
> constructor. It can appear in any place but the first in ordinary operators.
> For example:
>        (:) :: a -> [a] -> [a]  -- first symbol is ':' => constructor
>        (:+) :: (RealFloat a) => a -> a -> Complex a    -- constructor
>        (/:/) :: a -> b -> b    -- ':' not first symbol => ordinary 
> operator

Yes, that's what I meant, but you put it more nicely :-)

Is : really allowed in the middle of an operator like that?  (I can't
find it at all in the description of var-symbol on the last page in
http://www.cs.uu.nl/wiki/pub/FP/CourseLiterature/haskellsyntax-main.pdf
, hence my question.)

/M

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


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

Message: 2
Date: Wed, 4 Mar 2009 15:56:01 +0100
From: Daniel Fischer <daniel.is.fisc...@web.de>
Subject: Re: [Haskell-beginners] infix and bind pseudonym
To: Magnus Therning <mag...@therning.org>
Cc: beginners@haskell.org, Michael Easter <codeto...@gmail.com>
Message-ID: <200903041556.01228.daniel.is.fisc...@web.de>
Content-Type: text/plain;  charset="utf-8"

Am Mittwoch, 4. März 2009 15:19 schrieb Magnus Therning:
> On Wed, Mar 4, 2009 at 1:20 PM, Daniel Fischer <daniel.is.fisc...@web.de> 
wrote:
> > Am Mittwoch, 4. März 2009 13:59 schrieb Magnus Therning:
> >> Yes, there are certain function names that allow infix usage without
> >> the back-ticks, the name 'chain' doesn't.  What those function names
> >> are?  Roughly you can say that functions that they are functions that
> >> look like binary operations, like + - ++ >>> etc.  I'm not sure I read
> >> the pangauage spec correctly, but it looks like operators are made up
> >> of the following characters !...@#$%^&*+-./\|<=>?~ (IIRC ':' has a
> >> special meaning in that it's allowed in "constructors", cf 1:2:[]).
> >
> > ':' is the symbol-equivalent of an upper case letter, so it's special
> > only if it's the first symbol of an operator name, then the operator is a
> > constructor. It can appear in any place but the first in ordinary
> > operators. For example:
> >        (:) :: a -> [a] -> [a]  -- first symbol is ':' => constructor
> >        (:+) :: (RealFloat a) => a -> a -> Complex a    -- constructor
> >        (/:/) :: a -> b -> b    -- ':' not first symbol => ordinary
> > operator
>
> Yes, that's what I meant, but you put it more nicely :-)
>
> Is : really allowed in the middle of an operator like that?  (I can't
> find it at all in the description of var-symbol on the last page in
> http://www.cs.uu.nl/wiki/pub/FP/CourseLiterature/haskellsyntax-main.pdf
> , hence my question.)

When in doubt, consult the report, 
http://haskell.org/onlinereport/lexemes.html

Section 2.4:
varsym 
-> 
( symbol {symbol | :})<reservedop | dashes> 


consym 
-> 
(: {symbol | :})<reservedop> 


reservedop 
-> 
.. | : | :: | = | \ | | | <- | -> | @ | ~ | => 

>
> /M

Cheers,
Daniel



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

Message: 3
Date: Wed, 4 Mar 2009 21:31:01 +0000 (UTC)
From: 7stud <bbxx789_0...@yahoo.com>
Subject: [Haskell-beginners] Re: let indenting problems
To: beginners@haskell.org
Message-ID: <loom.20090304t213028-...@post.gmane.org>
Content-Type: text/plain; charset=us-ascii

Heinrich Apfelmus <apfelmus <at> quantentunnel.de> writes:
> 

Thanks for the explanations.






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

Message: 4
Date: Wed, 4 Mar 2009 21:50:30 +0000 (UTC)
From: 7stud <bbxx789_0...@yahoo.com>
Subject: [Haskell-beginners] Re: let indenting problems
To: beginners@haskell.org
Message-ID: <loom.20090304t213302-...@post.gmane.org>
Content-Type: text/plain; charset=utf-8

Francesco Bochicchio <bieffe62 <at> gmail.com> writes:
> In all three cases, after  the keyword 'in' 
> you need a **full** expression,
> and neither a where clause nor a set of matches are a full expression 
> by themselves. An expression is either a function apllication or a 'statement'
> like if or case, or maybe something more I can't recall.
> 

Thanks for the help.

> Don't know of any other editors with the same capability for haskell, though,
> and if you are not an emacs user, learning 
> the not-so-standard ways of emacs might offset the benefits of having
> syntax hints. 


I don't know emacs.   I use vim.  I may have to give emacs a try.










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

Message: 5
Date: Wed, 4 Mar 2009 21:54:05 +0000 (UTC)
From: 7stud <bbxx789_0...@yahoo.com>
Subject: [Haskell-beginners] Top beginner mistakes
To: beginners@haskell.org
Message-ID: <loom.20090304t215044-...@post.gmane.org>
Content-Type: text/plain; charset=us-ascii

Here are my top three:

1) Putting an equals sign after a function name when using guards:

myfunction x y =
    | x < 2              = "a"
    | y > 20             = "b"
    | otherwise          = "c"


dhask.hs:2:4: parse error on input `|'
Failed, modules loaded: none.



2) Writing "if" in front of the guard conditions:

myfunction x y =
    | if x < 2           = "a"
    | if y > 20          = "b"
    | otherwise          = "c"


dhask.hs:2:25: parse error on input `='
Failed, modules loaded: none.



3) Not putting parentheses around arguments of the form x:xs

dosomething x:xs = head xs

dhask.hs:1:0: Parse error in pattern
Failed, modules loaded: none.


In all three cases, the error messages don't help spot the problem.





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

Message: 6
Date: Wed, 4 Mar 2009 17:45:00 -0500
From: Patrick LeBoutillier <patrick.leboutill...@gmail.com>
Subject: [Haskell-beginners] Basic experimenting with monads
To: beginners <beginners@haskell.org>
Message-ID:
        <b217a64f0903041444k726cf7f2o4b73766dcc6a2...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi all,

I'm pretty much a haskell newbie (reading RWH at chapter 15) and I'm
trying to understand monads better, more specifically the mechanics of
>>= chains.

For example, take the following code:

skip :: IO a -> IO String
skip a = return "?"

main = do
    putStrLn "1"
    n <- skip $ do
        putStrLn "2"
        putStrLn "3"
    putStrLn $ "skipped " ++ n
    putStrLn "4"

When I run it, it prints, as expected:

1
skipped ?
4

My understanding is that what is really "passed" to the skip function
is something like this:

putStrLn "2" >> putStrLn "3"

Here is my question: is it possible for the skip function to return
the number of actions that were skipped? In other words, is it
possible to go through the chain above without executing the actions
but counting them instead?

It seems to me it should be possible to do this, in a way similar to
what happens when executing the Maybe monad (a return value of Nothing
triggers the return of other Nothing values, but the full length of
the chain is still executed (RWH, p.38)).

Am I on the right track here?


Thanks a lot,

Patrick






-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada


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

Message: 7
Date: Wed, 4 Mar 2009 15:58:18 -0800
From: Conrad Meyer <kon...@tylerc.org>
Subject: Re: [Haskell-beginners] Basic experimenting with monads
To: beginners@haskell.org
Message-ID: <200903041558.18358.kon...@tylerc.org>
Content-Type: text/plain;  charset="iso-8859-1"

On Wednesday 04 March 2009 02:45:00 pm Patrick LeBoutillier wrote:
> My understanding is that what is really "passed" to the skip function
> is something like this:
>
> putStrLn "2" >> putStrLn "3"
>
> Here is my question: is it possible for the skip function to return
> the number of actions that were skipped? In other words, is it
> possible to go through the chain above without executing the actions
> but counting them instead?

I am also a beginner (so I am probably wrong), but I think actually the (>>) 
function turns two IO actions into one, and your function only recieves that 
one IO action. I am not sure if that can be decomposed or not (probably not).

Regards,
-- 
Conrad Meyer <kon...@tylerc.org>



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

Message: 8
Date: Wed, 4 Mar 2009 17:03:45 -0800
From: Alexander Dunlap <alexander.dun...@gmail.com>
Subject: Re: [Haskell-beginners] Basic experimenting with monads
To: Conrad Meyer <kon...@tylerc.org>
Cc: beginners@haskell.org
Message-ID:
        <57526e770903041703jcc85a83rbd66b448ac2f6...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On Wed, Mar 4, 2009 at 3:58 PM, Conrad Meyer <kon...@tylerc.org> wrote:
> On Wednesday 04 March 2009 02:45:00 pm Patrick LeBoutillier wrote:
>> My understanding is that what is really "passed" to the skip function
>> is something like this:
>>
>> putStrLn "2" >> putStrLn "3"
>>
>> Here is my question: is it possible for the skip function to return
>> the number of actions that were skipped? In other words, is it
>> possible to go through the chain above without executing the actions
>> but counting them instead?
>
> I am also a beginner (so I am probably wrong), but I think actually the (>>)
> function turns two IO actions into one, and your function only recieves that
> one IO action. I am not sure if that can be decomposed or not (probably not).
>
> Regards,
> --
> Conrad Meyer <kon...@tylerc.org>
>

Actually, you're exactly right. The type of (>>) is

(>>) :: IO a -> IO b -> IO b.

Since there is no primitive IO b -> Int (which counts the number of
actions in the IO action), there's no way to count them.

However, there is a way to solve the original problem. If you define a
list of the actions (let a = [putStrLn "2", putStrLn "3"]) then you
can use length to count the number of actions in the list and
sequence_ (:: [IO a] -> IO (), from Control.Monad) to run them.

Alex


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

Message: 9
Date: Thu, 05 Mar 2009 20:08:08 +0900
From: Benjamin L.Russell <dekudekup...@yahoo.com>
Subject: [Haskell-beginners] Re: Top beginner mistakes
To: beginners@haskell.org
Message-ID: <0javq4lvk9ve9jarncecrfk26pe06jl...@4ax.com>
Content-Type: text/plain; charset=us-ascii

Those are excellent examples!

I have just added them to HaskellWiki on the following page, and
credited them to you:

Common Misunderstandings - HaskellWiki
http://www.haskell.org/haskellwiki/Common_Misunderstandings

Good work!

-- Benjamin L. Russell

On Wed, 4 Mar 2009 21:54:05 +0000 (UTC), 7stud
<bbxx789_0...@yahoo.com> wrote:

>Here are my top three:
>
>1) Putting an equals sign after a function name when using guards:
>
>myfunction x y =
>    | x < 2              = "a"
>    | y > 20             = "b"
>    | otherwise          = "c"
>
>
>dhask.hs:2:4: parse error on input `|'
>Failed, modules loaded: none.
>
>
>
>2) Writing "if" in front of the guard conditions:
>
>myfunction x y =
>    | if x < 2           = "a"
>    | if y > 20          = "b"
>    | otherwise          = "c"
>
>
>dhask.hs:2:25: parse error on input `='
>Failed, modules loaded: none.
>
>
>
>3) Not putting parentheses around arguments of the form x:xs
>
>dosomething x:xs = head xs
>
>dhask.hs:1:0: Parse error in pattern
>Failed, modules loaded: none.
>
>
>In all three cases, the error messages don't help spot the problem.
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
"Furuike ya, kawazu tobikomu mizu no oto." 
-- Matsuo Basho^ 



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

Message: 10
Date: Thu, 5 Mar 2009 12:19:55 +0000 (UTC)
From: 7stud <bbxx789_0...@yahoo.com>
Subject: [Haskell-beginners] Re: Top beginner mistakes
To: beginners@haskell.org
Message-ID: <loom.20090305t121249-...@post.gmane.org>
Content-Type: text/plain; charset=us-ascii

Benjamin L. Russell <DekuDekuplex <at> Yahoo.com> writes:
> Those are excellent examples!
> 
> I have just added them to HaskellWiki on the following page, and
> credited them to you:
> 
> Common Misunderstandings - HaskellWiki
> http://www.haskell.org/haskellwiki/Common_Misunderstandings
> 
> Good work!
> 

Thanks!  I made a copy and paste error though.  The second example
still has the equals sign:

myfunction x y  =

which would produce the same error message as the first example.
The equals sign should be stricken from the second example.

Also, no quotes around 7stud in the attribution! lol.










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

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


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

Reply via email to