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: WWAAA... I hate monads (Ertugrul Soeylemez)
   2. Re:  problem cabal install'ing hmatrix (Erik Quaeghebeur)
   3. Re:  generating the set of all finite-valued ...
      (Erik Quaeghebeur)
   4.  Re: computation vs function (Ertugrul Soeylemez)
   5. Re:  problem cabal install'ing hmatrix (Alberto Ruiz)
   6. Re:  Re: WWAAA... I hate monads ([email protected])
   7. Re:  generating the set of all finite-valued ... (Jan Jakubuv)
   8. Re:  generating the set of all finite-valued ... (Brent Yorgey)


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

Message: 1
Date: Thu, 23 Apr 2009 21:42:56 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: [Haskell-beginners] Re: WWAAA... I hate monads
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

Hello people,

thanks for all your positive comments about my tutorial, both here and
through direct email.  I appreciate that very much. =)

I'm glad that my work is helpful to the community.

Greets,
Ertugrul.


Colin Paul Adams <[email protected]> wrote:

> >>>>> "Daniel" == Daniel Carrera <[email protected]> writes:
>
>     Daniel> Sam Martin wrote:
>     >>> This is excellent:
>     >>>
>     >>> http://ertes.de/articles/monads.html
>     >>
>     >> Wow. That really is a great tutorial! Suddenly the world
>     >> becomes clear...
>     >>
>     >> Definitely gets my vote as must read material.
>
>     Daniel> +1
>
>     Daniel> I was very impressed too. And I am not easy to impress
>     Daniel> when it comes to documentation. I plan to read it a second
>     Daniel> time to solidify some of the ideas, but on my first
>     Daniel> reading my understanding of Monads increased by leaps and
>     Daniel> bounds.
>
>     Daniel> Ertugrul deserves to be commended, and this tutorial
>     Daniel> should be made more prominent on haskell.org.
>
> I think so.
> I've read VERY MANY tutorials on monads, and they were all confusing -
> except this one.



-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/




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

Message: 2
Date: Thu, 23 Apr 2009 23:54:15 +0200 (CEST)
From: Erik Quaeghebeur <[email protected]>
Subject: Re: [Haskell-beginners] problem cabal install'ing hmatrix
To: Alberto Ruiz <[email protected]>
Cc: [email protected]
Message-ID: <alpine.lnx.2.00.0904232349030.5...@ybpnyubfg>
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed

>>  Original message:
>> > > 
>> > >   $ cabal install hmatrix
>> > >   Resolving dependencies...
>> > >   Configuring hmatrix-0.5.1.1...
>> > >   Preprocessing library hmatrix-0.5.1.1...
>> > >   running dist/build/Numeric/GSL/Special/Internal_hsc_make failed
>> > >   command was: dist/build/Numeric/GSL/Special/Internal_hsc_make
>> > > >   dist/build/Numeric/GSL/Special/Internal.hs
>> > >   cabal: Error: some packages failed to install:
>> > >   hmatrix-0.5.1.1 failed during the building phase. The exception was:
>> > >   exit: ExitFailure 1
>> > > 
>> > >   What should I do to diagnose/resolve this problem?

On Thu, 23 Apr 2009, Alberto Ruiz wrote:
>
> Probably a dependency not mentionend in extra-libraries is missing. There is 
> not a standard way to link -llapack. For instance, in Ubuntu/Debian we only 
> need gsl and lapack:
>
> $ ld -lgsl -llapack
> ld: warning: cannot find entry symbol _start; not setting start address
>
> This means that everything is ok, but in other systems we may also need some 
> of -l[gsl]cblas, -lgfortran, or -lf77blas, -latlas, -lgcc_s, etc.
>
> Try to find the correct libraries with
>
> $ ld -lgsl -llapack -lgslcblas

# ld -lgsl -llapack -lgslcblas
ld: warning: cannot find entry symbol _start; not setting start address

> or other combinations, and modify the extra-libraries field in hmatrix.cabal. 
> In any case, I will try to add cabal flags to cover common situations. (There 
> is also a possible issue with ghc-6.8 that must be fixed, but the library 
> should work ok with 6.10).

# ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.2


It seems we still don't know the cause; any more things I can do to 
diagnose?

I'll also investigate the possibilities of resolving this issue by using 
the gentoo haskell overlay or non-stable versions of ghc (6.10) in 
Gentoo's repository.

Erik


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

Message: 3
Date: Fri, 24 Apr 2009 00:16:06 +0200 (CEST)
From: Erik Quaeghebeur <[email protected]>
Subject: Re: [Haskell-beginners] generating the set of all
        finite-valued ...
To: Jan Jakubuv <[email protected]>
Cc: [email protected]
Message-ID: <alpine.lnx.2.00.0904240003420.5...@ybpnyubfg>
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed

> On Thu, Apr 23, 2009 at 03:45:27PM +0200, Erik Quaeghebeur wrote:
>>
>> I'd like to lazily generate the set of all {-1,0,1}-valued functions on
>> {'a','b','c'}? How should I best approach this. I was thinking about
>> generalizing the power set definition

On Thu, 23 Apr 2009, Jan Jakubuv wrote:
>
> Try to start with this:
>
>    mapM (\x -> [(x,-1),(x,0),(x,1)]) ['a','b','c']

Aha. Great. Thanks, Jan. And now I realized that I don't really care about 
the domain, so I said:

Prelude> let m = mapM (\x -> [(x,-1),(x,0),(x,1)]) ['a','b','c']
Prelude> map (\x -> snd $ unzip x) m
[[-1,-1,-1],[-1,-1,0],[-1,-1,1],[-1,0,-1],[-1,0,0],[-1,0,1],[-1,1,-1],[-1,1,0],[-1,1,1],[0,-1,-1],[0,-1,0],[0,-1,1],[0,0,-1],[0,0,0],[0,0,1],[0,1,-1],[0,1,0],[0,1,1],[1,-1,-1],[1,-1,0],[1,-1,1],[1,0,-1],[1,0,0],[1,0,1],[1,1,-1],[1,1,0],[1,1,1]]

Any more direct way of doing this? (Still trying to understand how the 
mapM works... I've found it's sequence.map, but that doesn't really help.)

The next step will be to choose a good data format for what I'm trying to 
achieve. The functions (now represented as lists) would more naturally be 
represented as column matrices, e.g., from Numeric.LinearAlgebra of 
hmatrix, as I'll be needing some linear system solver. I can do the 
transition from lists to that, but I'm afraid they don't give me the 
necessary flexibility; I'd need to filter them based on (maximum/minimum) 
component values and sum them and such. Any thoughts on that?

Erik


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

Message: 4
Date: Fri, 24 Apr 2009 00:56:50 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: [Haskell-beginners] Re: computation vs function
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

Daniel Carrera <[email protected]> wrote:

> > What I refer to as a 'computation' in the article is actually just a
> > value of type 'Monad m => m a'.  I have chosen that term, because
> > you can apply it to any monad I've seen.  As mentioned in section 5,
> > you can think of 'Just 3' as being a computation, which results in
> > 3.  But it's important that this is not a function, but just an
> > independent value.
>
> Thanks.
>
> I think the article would benefit from making the meaning of
> computation clearer. The word computation appears in the tutorial 51
> times before section 5. That means that when I tried to go back for a
> definition of computation I couldn't find one.
>
> The first place you use the word computation is in the preamble, but
> that's not a good place to define terms. The second time you use the
> word computation is in section 2 "Motivation". This might be a good
> place to define the term. The Motivation section already defines
> several terms (referentially transparent, purely functional, etc), so
> it seems like a good place to define computation as well.
>
> In section 2 we can't say "Monad => m a" or "Just 3" because the terms
> are not introduced yet. Perhaps you could say something like this:
>
> <idea>
> The word 'computation' here is not a technical term. I use it to refer
> to something that returns a value without taking in any
> parameters. For example (m a) is a computation that takes no
> parameters but returns a value of type 'a' whereas (a -> b) is a
> function that takes a parameter of type 'a' and returns a value of
> type 'b'. It is important that a computation is not a function, but an
> independent value.
> </idea>
>
> I think that adding that as the third paragraph in the Motivation
> section would be helpful. In addition, in the Preamble, when you use
> the word computation, I would add "(see next section)".

Yes, you're right about that and I'm going to restructure it a bit, when
I've got some time.  But I can't do much more than clarifying that the
term is just an intuition and that it shouldn't be confused with
functions, maybe writing a bit more about the difference between the
two.

This is precisely the reason why I mentioned Brent's blog post [1].  He
hit the nail right on the head.  I think a monads tutorial is supposed
to be read twice.


> Question: Would it be reasonable to say that a computation is a
> wrapper?  I'm not sure, because I don't know if a computation always
> results in the *same* value (you know, side-effects). I know that
> "Just 3" always results in 3, but is that universal?

Don't confuse the concept of a computation with the concept of running
it.  A computation does not result at all, unless you have a notion of
running it.  That notion defines what it means for a computation to
"result".  An IO computation can give different results in each run, a
Maybe computation can't.  I'm giving a few examples to make this
clearer:

* IO:  Running an IO computation is possible through running the
  program.  There is no safe notion of running a computation from
  Haskell.  This is intentional, as you can see in more detail in the
  tutorial.

* Parser:  Running a Parser computation is possible through parsing a
  text.  The result is the outcome of that process.

* State s:  Running a 'State s'-computation means calling the underlying
  function, which implements the stateful computation, with an initial
  state value.

* Maybe and []:  Running a Maybe or list computation is extracting its
  value through support functions (fromJust, maybe, head, tail, etc.) or
  through pattern matching.

Replace "wrapper" by "container", then you have another intuition for
monadic values.  An IO container contains some value, which depends on
world state, the Maybe container contains some value or not, the list
container contains arbitrarily many values, the Parser container
contains the outcome of parsing something, etc.

All in all, a monad is a wrapper type, but it doesn't exactly wrap
values.  There is an interesting counter-example, the unit monad:

  data Unit a = Unit

Think of it as a Maybe monad, which is constrained to Nothing.  There is
no result of the computation, there is no value in the container, there
is no whatever in the burrito.  Nonetheless Unit is a perfectly valid
monad and here is its instance:

  instance Monad Unit where
    return  = const Unit
    _ >>= _ = Unit


Greets,
Ertugrul.


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/




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

Message: 5
Date: Fri, 24 Apr 2009 11:23:10 +0200
From: Alberto Ruiz <[email protected]>
Subject: Re: [Haskell-beginners] problem cabal install'ing hmatrix
To: Erik Quaeghebeur <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Erik, if you get

 > # ld -lgsl -llapack -lgslcblas
 > ld: warning: cannot find entry symbol _start; not setting start address

perhaps you only need to uncomment line 141 in hmatrix.cabal and try 
"cabal install" in that folder.

This is not the default because we prefer to link with a possibly 
optimized cblas. Clearly hmatrix requires a previous configure step.

Alberto

Erik Quaeghebeur wrote:
>>>  Original message:
>>> > > > >   $ cabal install hmatrix
>>> > >   Resolving dependencies...
>>> > >   Configuring hmatrix-0.5.1.1...
>>> > >   Preprocessing library hmatrix-0.5.1.1...
>>> > >   running dist/build/Numeric/GSL/Special/Internal_hsc_make failed
>>> > >   command was: dist/build/Numeric/GSL/Special/Internal_hsc_make
>>> > > >   dist/build/Numeric/GSL/Special/Internal.hs
>>> > >   cabal: Error: some packages failed to install:
>>> > >   hmatrix-0.5.1.1 failed during the building phase. The exception 
>>> was:
>>> > >   exit: ExitFailure 1
>>> > > > >   What should I do to diagnose/resolve this problem?
> 
> On Thu, 23 Apr 2009, Alberto Ruiz wrote:
>>
>> Probably a dependency not mentionend in extra-libraries is missing. 
>> There is not a standard way to link -llapack. For instance, in 
>> Ubuntu/Debian we only need gsl and lapack:
>>
>> $ ld -lgsl -llapack
>> ld: warning: cannot find entry symbol _start; not setting start address
>>
>> This means that everything is ok, but in other systems we may also 
>> need some of -l[gsl]cblas, -lgfortran, or -lf77blas, -latlas, -lgcc_s, 
>> etc.
>>
>> Try to find the correct libraries with
>>
>> $ ld -lgsl -llapack -lgslcblas
> 
> # ld -lgsl -llapack -lgslcblas
> ld: warning: cannot find entry symbol _start; not setting start address
> 
>> or other combinations, and modify the extra-libraries field in 
>> hmatrix.cabal. In any case, I will try to add cabal flags to cover 
>> common situations. (There is also a possible issue with ghc-6.8 that 
>> must be fixed, but the library should work ok with 6.10).
> 
> # ghc --version
> The Glorious Glasgow Haskell Compilation System, version 6.8.2
> 
> 
> It seems we still don't know the cause; any more things I can do to 
> diagnose?
> 
> I'll also investigate the possibilities of resolving this issue by using 
> the gentoo haskell overlay or non-stable versions of ghc (6.10) in 
> Gentoo's repository.
> 
> Erik
> 


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

Message: 6
Date: Fri, 24 Apr 2009 07:11:53 -0300
From: [email protected]
Subject: Re: [Haskell-beginners] Re: WWAAA... I hate monads
To: Ertugrul Soeylemez <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Thu, Apr 23, 2009 at 09:42:56PM +0200, Ertugrul Soeylemez wrote:
> Hello people,
> 
> thanks for all your positive comments about my tutorial, both here and
> through direct email.  I appreciate that very much. =)
> 
> I'm glad that my work is helpful to the community.

Would you provide a PDF version along with the HTML version?

Regards,

Romildo

> Colin Paul Adams <[email protected]> wrote:
> 
> > >>>>> "Daniel" == Daniel Carrera <[email protected]> writes:
> >
> >     Daniel> Sam Martin wrote:
> >     >>> This is excellent:
> >     >>>
> >     >>> http://ertes.de/articles/monads.html
> >     >>
> >     >> Wow. That really is a great tutorial! Suddenly the world
> >     >> becomes clear...
> >     >>
> >     >> Definitely gets my vote as must read material.
> >
> >     Daniel> +1
> >
> >     Daniel> I was very impressed too. And I am not easy to impress
> >     Daniel> when it comes to documentation. I plan to read it a second
> >     Daniel> time to solidify some of the ideas, but on my first
> >     Daniel> reading my understanding of Monads increased by leaps and
> >     Daniel> bounds.
> >
> >     Daniel> Ertugrul deserves to be commended, and this tutorial
> >     Daniel> should be made more prominent on haskell.org.
> >
> > I think so.
> > I've read VERY MANY tutorials on monads, and they were all confusing -
> > except this one.


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

Message: 7
Date: Fri, 24 Apr 2009 11:36:44 +0100
From: Jan Jakubuv <[email protected]>
Subject: Re: [Haskell-beginners] generating the set of all
        finite-valued ...
To: Erik Quaeghebeur <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Fri, Apr 24, 2009 at 12:16:06AM +0200, Erik Quaeghebeur wrote:
>
> Aha. Great. Thanks, Jan. And now I realized that I don't really care 
> about the domain, so I said:
>
> Prelude> let m = mapM (\x -> [(x,-1),(x,0),(x,1)]) ['a','b','c']
> Prelude> map (\x -> snd $ unzip x) m
> [[-1,-1,-1],[-1,-1,0],[-1,-1,1],[-1,0,-1],[-1,0,0],[-1,0,1],[-1,1,-1],[-1,1,0],[-1,1,1],[0,-1,-1],[0,-1,0],[0,-1,1],[0,0,-1],[0,0,0],[0,0,1],[0,1,-1],[0,1,0],[0,1,1],[1,-1,-1],[1,-1,0],[1,-1,1],[1,0,-1],[1,0,0],[1,0,1],[1,1,-1],[1,1,0],[1,1,1]]
>
> Any more direct way of doing this? (Still trying to understand how the  
> mapM works... I've found it's sequence.map, but that doesn't really 
> help.)
>

Well, you can write:

    mapM (const [-1,0,1]) [1..3]

mapM takes a function which returns a computation for a given argument. In
this case the function always returns the computation [-1,0,1] which you can
think of as a non-deterministic computation resulting in either -1, or 0, or
1. This computation is executed for every value in the list [1..3] and
because this list has three values the execution results in [x,y,z] where
each of x, y, and z is either -1, or 0, or -1. This gives you all
variations. You can also write:

    [[x,y,z] | x<-[-1,0,1], y<-[-1,0,1], z<-[-1,0,1]]

Sincerely,
    Jan.



-- 
Heriot-Watt University is a Scottish charity
registered under charity number SC000278.



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

Message: 8
Date: Fri, 24 Apr 2009 09:24:00 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] generating the set of all
        finite-valued ...
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Fri, Apr 24, 2009 at 11:36:44AM +0100, Jan Jakubuv wrote:
> On Fri, Apr 24, 2009 at 12:16:06AM +0200, Erik Quaeghebeur wrote:
> >
> > Aha. Great. Thanks, Jan. And now I realized that I don't really care 
> > about the domain, so I said:
> >
> > Prelude> let m = mapM (\x -> [(x,-1),(x,0),(x,1)]) ['a','b','c']
> > Prelude> map (\x -> snd $ unzip x) m
> > [[-1,-1,-1],[-1,-1,0],[-1,-1,1],[-1,0,-1],[-1,0,0],[-1,0,1],[-1,1,-1],[-1,1,0],[-1,1,1],[0,-1,-1],[0,-1,0],[0,-1,1],[0,0,-1],[0,0,0],[0,0,1],[0,1,-1],[0,1,0],[0,1,1],[1,-1,-1],[1,-1,0],[1,-1,1],[1,0,-1],[1,0,0],[1,0,1],[1,1,-1],[1,1,0],[1,1,1]]
> >
> > Any more direct way of doing this? (Still trying to understand how the  
> > mapM works... I've found it's sequence.map, but that doesn't really 
> > help.)
> >
> 
> Well, you can write:
> 
>     mapM (const [-1,0,1]) [1..3]

Better yet (in my opinion), you can just write

      sequence (replicate 3 [-1,0,1])

which is really the same thing, since mapM = sequence . map.  Mapping
(const [-1,0,1]) over [1..3] yields [[-1,0,1], [-1,0,1], [-1,0,1]],
that is, (replicate 3 [-1,0,1]).  It's the 'sequence' that does the
magic of selecting an item from each of the three lists in all
possible ways.

-Brent


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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 10, Issue 26
*****************************************

Reply via email to