Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Relation between monads and computations (Dmitriy Matrosov)
2. Re: Relation between monads and computations (Brent Yorgey)
3. Cabal complains that cabal-dev ?indirectly depends on
multiple versions of the same package?, even though it
(apparently) does not (James Fisher)
----------------------------------------------------------------------
Message: 1
Date: Wed, 15 Feb 2012 22:31:03 +0300
From: Dmitriy Matrosov <[email protected]>
Subject: Re: [Haskell-beginners] Relation between monads and
computations
To: [email protected]
Message-ID:
<CAFdVUFma-RUx3=kuev06xknzpycm5hxlqv2sqqeboy2omdf...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Hi Brent, thanks for the answer!
> On Thu, Feb 09, 2012 at 02:02:59PM +0300, Dmitriy Matrosov wrote:
> > Hi, everyone!
> >
> > Not so long ago i started to learn haskell, and now i have a question
> > about relation between monads and computations. In fact, i think, that
> > i understand it and write some explanation for myself, but i'm not
> > sure whether my explanation is correct or not, and will be very
> > thankful if someone check it :) Here it is (i don't know category
> > theory and my math knowledge is poor, so if i accidently use some
> > terms from them incorrectly - it was just my understanding).
>
> You say you have a question, but from reading the below I am not sure
> what your question is...
The original question was: "Am i right?". I just try to understand what monad
is, and, because it is referred as computations, i try to understand why.
E.g. from [2], end of section 2.1:
"Just as the type Value represents a value, the type M Value can be thought of
as representing a computation. The purpose of unitM is to coerce a value into
computation; the purpose of bindM is to evaluate a computation, yielding a
value."
Similarly, it often referred as computation in [1]. (Though, i don't finish
reading both of these papers).
> Let me say first that while "monad" has a precise technical
> definition, "computation" does not. So "the relation between monads
> and computations" is not well-defined unless it is specified what you
> mean by "computation". There are many ways to model different ideas
> of "computation"; one of them is monads, but that is not the only way.
May i ask you then, what is the precise definition of monad? The only other
definition besides "the computation", which i know, is "a triple of (M, unitM,
bindM)" (from [2]), but it does not explain to me what this may have common
with computations.
Definition of computation, which i assume, is something (may be better to say
triple), which have initial value, some transformation (function? or action?)
and the result. Is this definition correct?
> > Monads and computations.
> >
> > Generally computation consists of initial value, computation itself and the
> > result. So it can be illustrated as:
> >
> > type a (M b) b
> > data I ------> C <--------- E
> > f ConstrM
> >
> > I :: a
> > f :: a -> M b
> > data M a = ContrM a | ...
> > E :: b
> >
> > Let's see what happens: i take initial value I of type a and map it to some
> > computation C (of type (M b)) using function f. Then, exist such value E of
> > type b, that C = (ConstrM E). This value E will be the result of
> > computation.
>
> That last part ("there exists a value E of type b ...") doesn't seem
> right to me. There is no guarantee or requirement that a monad M be
> defined so there is a constructor wrapping the "result". For example,
> consider the list type:
>
> data [a] = [] | (a : [a])
>
> In this case a function of type a -> [b] might produce a list
> containing multiple values of type b. There is no single value of
> type b which is the "result", and there is no constructor which wraps
> a single value of type b into a list.
Well, you're right, this should be rewritten. Here i just try to recognise in
monad all three parts of my computation definition. Then: "the result of
computation is values E1,.. En of type b from which using constructors
ConstrM1,.. ContrMk may be made computation C of type M b". Is the idea right?
> >
> > Now, using fucntions unitM and bindM there is possibly to convert arbitrary
> > function (k :: a -> b), which makes from initial value of type a value of
> > type
> > b, into terms of general computation (represented by type M).
>
> Yes, (k :: a -> b) can be converted into a function of type (a -> M
> b), but I think you have made it more complicated than necessary. All
> you need to do is (unitM . k).
Hmm, so i was wrong here. Initially, i suppose, that the purpose of bindM is
to convert function of type (a -> b) into function of type (a -> M b), but now
i see it is wrong. Mentioned above quote from [2] says, that "the purpose of
bindM is to evaluate a computation, yielding a value.", which sounds a little
unfinished to me. Then may be: the purpose of bindM is to make composition
of functions of type (a -> M b) and (b -> M c) possible. Is this right?
References:
[1] Hal Daume III, "Yet another haskell tutorial"
[2] Philip Wadler, "The essence of functional programming"
--
Dmitriy Matrosov
------------------------------
Message: 2
Date: Wed, 15 Feb 2012 15:23:44 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Relation between monads and
computations
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Wed, Feb 15, 2012 at 10:31:03PM +0300, Dmitriy Matrosov wrote:
> Hi Brent, thanks for the answer!
>
> > On Thu, Feb 09, 2012 at 02:02:59PM +0300, Dmitriy Matrosov wrote:
> > > Hi, everyone!
> > >
> > > Not so long ago i started to learn haskell, and now i have a question
> > > about relation between monads and computations. In fact, i think, that
> > > i understand it and write some explanation for myself, but i'm not
> > > sure whether my explanation is correct or not, and will be very
> > > thankful if someone check it :) Here it is (i don't know category
> > > theory and my math knowledge is poor, so if i accidently use some
> > > terms from them incorrectly - it was just my understanding).
> >
> > You say you have a question, but from reading the below I am not sure
> > what your question is...
>
> The original question was: "Am i right?". I just try to understand what monad
> is, and, because it is referred as computations, i try to understand why.
> E.g. from [2], end of section 2.1:
> "Just as the type Value represents a value, the type M Value can be thought of
> as representing a computation. The purpose of unitM is to coerce a value into
> computation; the purpose of bindM is to evaluate a computation, yielding a
> value."
"The purpose of bindM is to evaluate a computation, yielding a value"
-- I have the greatest respect for Phil Wadler, but this is simply
wrong. From this description one would expect bindM to have the type
bindM :: M a -> a
but it does not.
> Similarly, it often referred as computation in [1]. (Though, i don't finish
> reading both of these papers).
Referring to values of type M a as "computations" is just supposed to
give some intuition, it is not a precise statement or a definition in
any sense. Monads are one possible formal framework for *defining*
what we mean by "computation". So trying to understand how monads are
computations will not get you anywhere. Instead, you should just try
to understand various examples of monads, and eventually you may get
some insight into how they can be thought of as "computations".
> May i ask you then, what is the precise definition of monad? The only other
> definition besides "the computation", which i know, is "a triple of (M, unitM,
> bindM)" (from [2]),
Yes. A monad is a triple (M, unitM, bindM) satisfying a certain set of
equational laws.
> but it does not explain to me what this may have common
> with computations.
Of course it doesn't. The definition of the Peano naturals does not
explain what they have to do with counting. The definition of a group
does not explain what it has to do with symmetry. Etc.
> Definition of computation, which i assume, is something (may be better to say
> triple), which have initial value, some transformation (function? or action?)
> and the result. Is this definition correct?
No. If you want to *define* computation, then in this context one
should say "the definition of computation is a value of type M a,
where M is a monad"! The word "computation" has been chosen because
this turns out to correspond to certain intuitive ideas people have
about that word but to really understand which intuitive ideas are
meant you will have to study the definition and examples of monads.
> >
> > In this case a function of type a -> [b] might produce a list
> > containing multiple values of type b. There is no single value of
> > type b which is the "result", and there is no constructor which wraps
> > a single value of type b into a list.
>
> Well, you're right, this should be rewritten. Here i just try to recognise in
> monad all three parts of my computation definition. Then: "the result of
> computation is values E1,.. En of type b from which using constructors
> ConstrM1,.. ContrMk may be made computation C of type M b". Is the
> idea right?
Not really. I advise you to forget the idea of defining what the
"result" of a computation is. As I said above, the quote from Phil
Wadler about running a computation and extracting its result is wrong
(or at the very least, extremely unhelpful).
>
> > >
> > > Now, using fucntions unitM and bindM there is possibly to convert
> > > arbitrary
> > > function (k :: a -> b), which makes from initial value of type a value of
> > > type
> > > b, into terms of general computation (represented by type M).
> >
> > Yes, (k :: a -> b) can be converted into a function of type (a -> M
> > b), but I think you have made it more complicated than necessary. All
> > you need to do is (unitM . k).
>
> Hmm, so i was wrong here. Initially, i suppose, that the purpose of bindM is
> to convert function of type (a -> b) into function of type (a -> M b), but now
> i see it is wrong. Mentioned above quote from [2] says, that "the purpose of
> bindM is to evaluate a computation, yielding a value.", which sounds a little
> unfinished to me. Then may be: the purpose of bindM is to make composition
> of functions of type (a -> M b) and (b -> M c) possible. Is this
> right?
Yes! In fact, there is a standard operator
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> (a -> m c)
which is defined in terms of bind. Implementing it is a good
exercise.
By the way, you may be interested in reading the Typeclassopedia:
http://www.haskell.org/haskellwiki/Typeclassopedia
-Brent
------------------------------
Message: 3
Date: Wed, 15 Feb 2012 21:15:43 +0000
From: James Fisher <[email protected]>
Subject: [Haskell-beginners] Cabal complains that cabal-dev
?indirectly depends on multiple versions of the same package?, even
though it (apparently) does not
To: [email protected]
Message-ID:
<CAC_Q48Ar2=cpnfsahkn8o3e2m4jhd_y1olruyu+wcmwupxp...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi all,
I've just asked this on SO as well (
http://stackoverflow.com/questions/9301122/haskell-cabal-package-indirectly-depends-on-multiple-versions-of-the-same-pack),
but to repeat the question:
After clearing out all of my cabal installed packages, I ran this following
session:
$ cabal update
Downloading the latest package list from hackage.haskell.org
james@bast:~/.cabal/packages$ cabal install cabal-dev
Resolving dependencies...
Downloading cabal-dev-0.9.1...
[1 of 1] Compiling Main (
/tmp/cabal-dev-0.9.124882/cabal-dev-0.9.1/Setup.hs,
/tmp/cabal-dev-0.9.124882/cabal-dev-0.9.1/dist/setup/Main.o )
Linking /tmp/cabal-dev-0.9.124882/cabal-dev-0.9.1/dist/setup/setup ...
Configuring cabal-dev-0.9.1...
Warning: This package indirectly depends on multiple versions of the same
package. This is highly likely to cause a compile failure.
package containers-0.4.2.1 requires array-0.4.0.0
package Cabal-1.14.0 requires array-0.4.0.0
package text-0.11.1.13 requires array-0.4.0.0
package deepseq-1.3.0.0 requires array-0.4.0.0
package containers-0.4.2.1 requires array-0.4.0.0
package HTTP-4000.2.2 requires array-0.4.0.0
package cabal-dev-0.9.1 requires containers-0.4.2.1
package Cabal-1.14.0 requires containers-0.4.2.1
package template-haskell-2.7.0.0 requires containers-0.4.2.1
Building cabal-dev-0.9.1...
Preprocessing executable 'ghc-pkg-6_8-compat' for cabal-dev-0.9.1...
<command line>: cannot satisfy -package-id
Cabal-1.14.0-4af45d3c8d10dc27db38ae0e7e5a952b:
Cabal-1.14.0-4af45d3c8d10dc27db38ae0e7e5a952b is unusable due to
missing or recursive dependencies:
array-0.4.0.0-46f61f5fd9543ebf309552ef84dccc86
containers-0.4.2.1-98f9aa15f9c08b13673dc9d89385f449
(use -v for more information)
cabal: Error: some packages failed to install:
cabal-dev-0.9.1 failed during the building phase. The exception was:
ExitFailure 1
$
So the reason I can't install cabal-dev is apparently either that
- it "indirectly depends on multiple versions of the same package."
However, cabal does not name the package that it claims cabal-dev requires
multiple versions of.
- Cabal-1.14.0 has "missing or recursive dependencies", specifically
somehow involving array-0.4.0.0 and containers-0.4.2.1.
A graph of the dependencies it lists confirms that neither of these claims
are true (or the dependencies it lists are false or incomplete):
[image: claimed dependency graph of cabal-dev-0.9.1]
*So: what am I missing? Who or what is incorrect: me, cabal, or one or more
packages?*
I am running:
$ cabal --version
cabal-install version 0.10.2
using version 1.10.1.0 of the Cabal library
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.4.1
$
Any help with this would be greatly appreciated. I get errors from cabal
fairly often and I usually end up giving up because I don't understand the
error.
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120215/9ac7cfe3/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 44, Issue 13
*****************************************