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:  Actions v. Functions (Jos? Romildo Malaquias)


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

Message: 1
Date: Sun, 20 Oct 2013 08:42:17 -0200
From: Jos? Romildo Malaquias <j.romi...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Actions v. Functions
Message-ID: <20131020104217.GA16877@jrm>
Content-Type: text/plain; charset=us-ascii

On Sat, Oct 19, 2013 at 07:03:22PM -0700, Rein Henrichs wrote:
> An action in this sense is just a function of type `Monad m => a -> m b'
> (or one where the monad is specified, like `a -> IO b'). This type
> signature fully specifies the "formal properties" of an action and shows
> that actions do not differ from functions: they are merely functions of a
> certain type.

I do not think so. An action is any value of a monadic type

   Monad m => m a

An action is just a computation in a monad. When executed, an action of
type `Monad m => m a' performs a computation and returns a value of type
`a'. The nature of the computation depends on the monad being
considered. For instance, actions in the IO monad, when executed,
interacts with the system (to do IO, for instance). Actions in the Maybe
monad may fail or succeed. Actions in the Reader monad can access an
environment carrying some information.

For some monads, an action may be a function, like in the Reader, Writer
and State monads. But that is not a requirement. Actions in the Maybe
and list monads are not functions.

> On Sat, Oct 19, 2013 at 3:23 PM, Brandon Allbery <allber...@gmail.com>wrote:
> 
> > On Sat, Oct 19, 2013 at 5:09 PM, MJ Williams <
> > matthewjwilliams...@gmail.com> wrote:
> >
> >>  For example, `main = do input <- getLine ...', where `getLine' is an
> >> action as distinguished from a function such as `main'.  Other examples of
> >> actions in Haskell include `print', `putStrLn' and

getLine and main are both actions in the IO monad.

> > Actions aren't so much a formal thing as a conceptual "handle" to help
> > with understanding monads. In particular, what a particular action
> > represents depends on the monad, and in some cases on the particular
> > implementation (for example, an IO action in GHC is a partially applied
> > function, but this is an implementation detail that does nothing to help
> > you understand how to work with it).


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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 64, Issue 32
*****************************************

Reply via email to