Dan Lior | 8 Mar 01:45 2013
Picon

Newbie

Hello, 

I'm new to Haskell and this is my first post to this forum. 

A few questions right off the bat:

1) Is this the right place for newbies to post questions about Haskell?
2) Is there a FAQ for Haskell questions? 
3) Are there any active Haskell user groups in the Chicago area?

A more technical question:

I'm messing around with basic Haskell examples on eclipse using the FP add-on running over GHC. 

The following code works:

pred :: Int -> Int
pred 0 = 0
pred n = n-1

The following code doesn't:

pred :: Int -> Int
pred 0 = 0
pred n+1 = n

Does anyone know why this might be? 

"Thanks" and "I apologize" in advance. 

(Continue reading)

Brandon Allbery | 8 Mar 01:56 2013
Picon

Re: Newbie

On Thu, Mar 7, 2013 at 7:45 PM, Dan Lior <sitiposit <at> gmail.com> wrote:
1) Is this the right place for newbies to post questions about Haskell?


This is most a list for announcements; beginners <at> haskell.org is better for these kinds of questions, and haskell-cafe <at> haskell.org for general discussion.

pred :: Int -> Int
pred 0 = 0
pred n+1 = n

n+k patterns were part of Haskell '98, but removed from Haskell 2010. You may be able to use the pragma

    {-# LANGUAGE NPlusKPatterns #-}

to turn them back on.

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b <at> gmail.com                                  ballbery <at> sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
_______________________________________________
Haskell mailing list
Haskell <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell
Ivan Lazar Miljenovic | 8 Mar 02:43 2013
Picon

Re: Newbie

On 8 March 2013 11:56, Brandon Allbery <allbery.b <at> gmail.com> wrote:
> On Thu, Mar 7, 2013 at 7:45 PM, Dan Lior <sitiposit <at> gmail.com> wrote:
>>
>> 1) Is this the right place for newbies to post questions about Haskell?
>
>
>
> This is most a list for announcements; beginners <at> haskell.org is better for
> these kinds of questions, and haskell-cafe <at> haskell.org for general
> discussion.
>
>> pred :: Int -> Int
>> pred 0 = 0
>> pred n+1 = n
>
>
> n+k patterns were part of Haskell '98, but removed from Haskell 2010. You
> may be able to use the pragma
>
>     {-# LANGUAGE NPlusKPatterns #-}
>
> to turn them back on.

Even then, you need to have "pred (n+1) = n".

>
> --
> brandon s allbery kf8nh                               sine nomine associates
> allbery.b <at> gmail.com                                  ballbery <at> sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
>
> _______________________________________________
> Haskell mailing list
> Haskell <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>

--

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic <at> gmail.com
http://IvanMiljenovic.wordpress.com
Henning Thielemann | 8 Mar 10:21 2013
Picon

Re: Newbie


On Thu, 7 Mar 2013, Dan Lior wrote:

> Hello,
>
> I'm new to Haskell and this is my first post to this forum.
>
> A few questions right off the bat:
>
> 1) Is this the right place for newbies to post questions about Haskell?
> 2) Is there a FAQ for Haskell questions?

    http://www.haskell.org/haskellwiki/Category:FAQ

> 3) Are there any active Haskell user groups in the Chicago area?

I don't know, but user groups can be found at:
    http://www.haskell.org/haskellwiki/Category:Community
Eduardo Ochs | 10 Mar 10:54 2001
Picon

Re: newbie

Frank Atanassow wrote:
> G Murali wrote (on 09-03-01 00:43 +0000):
> > I'm new to this monads stuff.. can you tell me what it is simply ?
> > an example would be highly appreciated.. i want it is very very
> > simple terms please..
>
> A monad on category C is a monoid in the category of endofunctors on C.
>
> Is that simple enough? ;)
>
> No? Then see "Using Monads" at http://haskell.org/bookshelf/
>
> (Sorry, I just couldn't resist!)

Uh-oh. I'm a junior categorist and toposopher and I confess that all
my few attempts to understand what Haskell's monads have to do with
the categorical notion of a monad have failed more or less miserably.
Can someone point me to a relevant paper, or give a quick explanation?

  Thanks in advance, and sorry for the dumb question,

    Eduardo Ochs
      http://angg.twu.net/
      edrx <at> inx.com.br

Joe English | 10 Mar 18:34 2001

Re: newbie

Eduardo Ochs wrote:
> Frank Atanassow wrote:
> > G Murali wrote (on 09-03-01 00:43 +0000):
> > > I'm new to this monads stuff.. can you tell me what it is simply ?
> > A monad on category C is a monoid in the category of endofunctors on C.
> > Is that simple enough? ;)
>
> Uh-oh. I'm a junior categorist and toposopher and I confess that all
> my few attempts to understand what Haskell's monads have to do with
> the categorical notion of a monad have failed more or less miserably.
> Can someone point me to a relevant paper, or give a quick explanation?

The relevant category for Haskell is the one in which
objects are types and arrows are functions.  The identity
arrow for object 't' is 'id' instantiated at type 'id :: t -> t',
and composition of arrows is function composition.

Single-argument type constructors like '[]', Maybe, etc.,
map types to types (objects to objects).  If equipped with a
suitable function 'fmap :: (a -> b) -> (T a -> T b)'
(i.e., taking arrows to arrows), they form a categorical
functor (specifically, an endofunctor), and can be made instances
of the Haskell Functor class.

Polymorphic functions are natural transformations: a function
'f :: forall a. F a -> G a' gives, for each object (type) 't'
an arrow from 'F t' to 'G t'.

One of the definitions of a monad is: a functor M equipped
with two natural transformations: eta : Id -> M and mu : MM -> M
(obeying certain laws).  Translating this into Haskell,
this is a type constructor M along with polymorphic functions
'return :: forall a. a -> M a' and 'join :: forall a. M (M a) -> M a'
(again obeying certain laws).

The 'join' function makes intuitive sense for "container-like"
monads like List (join = concat :: [[a]] -> [a]) and Maybe
(join (Just (Just x)) = Just x ; join Just Nothing = join Nothing = Nothing).
For other monads like state transformers, parsers, and IO it's
less intuitive, so it's more common to define Haskell Monads
in terms of the "bind" operation ">>=",

    (>>=) :: (M a) -> (a -> M b) -> M b

which is a close relative of the Kleisli composition operator.
Join, bind, and Kleisli composition are all interdefinable:

    (>>=) :: (M a) -> (a -> M b) -> M b
    join  :: M (M a) -> M a
    o     :: (b -> M c) -> (a -> M b) -> (a -> M c)

    m >>= k  = join (fmap k m)
    join mm  = mm >>= id
    f `o` g  = join . fmap f . g

Wadler's "Comprehending Monads" gives a very good presentation
using the fmap/return/join formulation (called map/unit/join
in that paper).  "The Essense of Functional Programming"
is another very good presentation using the return/>>=
formulation (there called "unitM/bindM").  See

    <URL: http://cm.bell-labs.com/cm/cs/who/wadler/topics/monads.html >

--Joe English

  jenglish <at> flightlab.com

Lars Henrik Mathiesen | 10 Mar 21:35 2001
Picon

Re: newbie

> From: Joe English <jenglish <at> flightlab.com>
> Date: Sat, 10 Mar 2001 09:34:28 -0800

> The relevant category for Haskell is the one in which
> objects are types and arrows are functions.  The identity
> arrow for object 't' is 'id' instantiated at type 'id :: t -> t',
> and composition of arrows is function composition.
> 
> Single-argument type constructors like '[]', Maybe, etc.,
> map types to types (objects to objects).  If equipped with a
> suitable function 'fmap :: (a -> b) -> (T a -> T b)'
> (i.e., taking arrows to arrows), they form a categorical
> functor (specifically, an endofunctor), and can be made instances
> of the Haskell Functor class.
> 
> Polymorphic functions are natural transformations: a function
> 'f :: forall a. F a -> G a' gives, for each object (type) 't'
> an arrow from 'F t' to 'G t'.
> 
> One of the definitions of a monad is: a functor M equipped
> with two natural transformations: eta : Id -> M and mu : MM -> M
> (obeying certain laws).  Translating this into Haskell,
> this is a type constructor M along with polymorphic functions
> 'return :: forall a. a -> M a' and 'join :: forall a. M (M a) -> M a'
> (again obeying certain laws).

However, in some expositions of category theory, the usefulness of
monads is justified because they 'belong' to a certain adjunction.

In Haskell you can't express the adjunction, only the monad, which may
take a little getting used to.

But how about the related concept of an M-algebra? That is, a type T
and a function 'xi :: M T -> T' so that these laws hold:
	 xi . eta       === id
	 xi . (fmap xi) === xi . mu

As it is, the List monad expresses the idea of the free monoid over a
set. A List-algebra is of course a general monoid:
	e   :: T
	e   = xi []
	(#) :: T -> T -> T
	(#) = \x y.xi [x y]

(And 'M a' is an M-algebra for any a, using xi = join).

And what you do every time you write 'foldl 0 +' in a program is to
give the xi of the additive monoid structure on the Num types.

Would it be useful to have functions that were polymorphic over
List-algebras? (Not that I have any idea how that might be possible to
express in Haskell).

Lars Mathiesen (U of Copenhagen CS Dep) <thorinn <at> diku.dk> (Humour NOT marked)

Frank Atanassow | 12 Mar 17:16 2001
Picon

Re: newbie

Lars Henrik Mathiesen wrote (on 10-03-01 20:35 -0000):
> However, in some expositions of category theory, the usefulness of
> monads is justified because they 'belong' to a certain adjunction.

You can regard a monad as arising from a particular adjunction but, although
every adjunction determines a unique monad, the converse is not true. In fact,
the collection of resolutions for a monad forms a category with adjunctions as
objects and certain functors as arrows. The adjunction which gives rise to the
Kleisli category is initial in this category. The terminal object is called
the Eilenberg-Moore category and it has as objects M-algebras, like your `xi',
and as arrows M-algebra homomorphisms.

> In Haskell you can't express the adjunction, only the monad, which may
> take a little getting used to.

I've been looking at this recently to find some canonical way to express how
to `deconstruct' monadic terms (i.e., how to run them). The idea is that you
build up monadic terms in the Kleisli category, somehow describe a resolution,
then use the initiality property of the Kleisli category to map the terms to
the category of the resolution, where you can use the adjunction to
destructure them.

> But how about the related concept of an M-algebra? That is, a type T
> and a function 'xi :: M T -> T' so that these laws hold:
> 	 xi . eta       === id
> 	 xi . (fmap xi) === xi . mu

If you reverse the sense of the last equation and regard the monad primitives
as constructors:

  xi (Eta x) = x
  xi (Mu m)  = xi (fmap xi m)

then this starts to look like a pattern-matching definition for folding a
monad regarded as an algebra. In fact, you can express the operators this way
in Haskell if you use are willing to use a nested datatype:

  data M a = Eta a | Mu (M (M a))

> Would it be useful to have functions that were polymorphic over
> List-algebras? (Not that I have any idea how that might be possible to
> express in Haskell).

I dunno if it is useful for List-algebras, but if you take your monad M as the
substitution monad generated by a term signature, then the the resolutions of
the monad can be regarded as a way of factoring M into a composition of
signatures which (I think) represent the values and redexes of the term
language. The Kleisli and E-M categories are extremal cases. In the Kleisli
category the redex functor is trivial; I think this is this is why you can use
it to pass around computations.

In the E-M category, the value functor is trivial, but I'm not sure what this
means precisely yet. For intermediate cases, you get a particular choice of
normal forms.  What I'm thinking is that an M-algebra for a language M gives
you a way of extending a denotational description of the normal forms to one
for the entire language, which is automatically sound for the equational
theory.

Which sounds useful to me for writing interpreters.

--

-- 
Frank Atanassow, Information & Computing Sciences, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-3261 Fax +31 (030) 251-379

Lars Henrik Mathiesen | 13 Mar 01:12 2001
Picon

Re: newbie

> Date: Mon, 12 Mar 2001 17:16:29 +0100
> From: Frank Atanassow <franka <at> cs.uu.nl>

> Lars Henrik Mathiesen wrote (on 10-03-01 20:35 -0000):
> > However, in some expositions of category theory, the usefulness of
> > monads is justified because they 'belong' to a certain adjunction.
> 
> You can regard a monad as arising from a particular adjunction but,
> although every adjunction determines a unique monad, the converse is
> not true. In fact, the collection of resolutions for a monad forms a
> category with adjunctions as objects and certain functors as arrows.
> The adjunction which gives rise to the Kleisli category is initial
> in this category. The terminal object is called the Eilenberg-Moore
> category and it has as objects M-algebras, like your `xi', and as
> arrows M-algebra homomorphisms.

Yes, I was aware of that --- I should perhaps have said that there's
typically a 'motivating' adjunction, often one involving a forgetful
functor. Which is generally different from the one into the Kleisli
category.

I read the rest of your post with great interest too, though I need to
work at it a bit before I think I understand all of it. MacLane is off
the shelf, and section IV.7 is scheduled to be worked though come the
weekend.

My own thoughts were a bit less ambitious, and I found out that
Haskell (at least hugs -98 +o) will in fact do what I had in mind:

> module Algebra () where

> class Monad m => Algebra m a where xi :: m a -> a

> instance (Num a) => Algebra [] a where
>  xi = foldl (+) 0

> instance Algebra [] [a] where xi = concat

> unit :: Algebra [] a => a
> unit = xi []

> (#) :: Algebra [] a => a -> a -> a
> x # y = xi [x, y]

   Prelude> :load Algebra.lhs
   Reading file "Algebra.lhs":

   Hugs session for:
   /usr/local/share/hugs/lib/Prelude.hs
   Algebra.lhs
   Algebra> unit :: Int
   0
   Algebra> unit :: Float
   0.0
   Algebra> unit :: [Char]
   ""
   Algebra> "foo" # "bar"
   "foobar"
   Algebra> (1::Int) # 2 # 3
   6

But perhaps I'm just easily amused.

Lars Mathiesen (U of Copenhagen CS Dep) <thorinn <at> diku.dk> (Humour NOT marked)

Eduardo Ochs | 10 Mar 11:08 2001
Picon

Re: newbie

Frank Atanassow wrote:
> G Murali wrote (on 09-03-01 00:43 +0000):
> > I'm new to this monads stuff.. can you tell me what it is simply ?
> > an example would be highly appreciated.. i want it is very very
> > simple terms please..
>
> A monad on category C is a monoid in the category of endofunctors on C.
>
> Is that simple enough? ;)
>
> No? Then see "Using Monads" at http://haskell.org/bookshelf/
>
> (Sorry, I just couldn't resist!)

Uh-oh.  I'm a junior categorist and toposopher and I confess that all
my few attempts to understand what Haskell's monads have to do with
the categorical notion of a monad have failed more or less miserably.
Can someone point me to a relevant paper, or give a quick explanation?

  Thanks in advance, and sorry for the dumb question,

    Eduardo Ochs
      http://angg.twu.net/
      edrx <at> inx.com.br

Leonid Bouriakovsky | 10 Mar 12:48 2001
Picon
Picon

Re: newbie

Perhaps, this paper will help: 

http://citeseer.nj.nec.com/62964.html

>Eduardo Ochs wrote:
>
>>Frank Atanassow wrote:
>>
>> A monad on category C is a monoid in the category of endofunctors on C.
>>
>> Is that simple enough? ;) 
>
>Uh-oh. I'm a junior categorist and toposopher and I confess that all
>my few attempts to understand what Haskell's monads have to do with
>the categorical notion of a monad have failed more or less miserably.
>Can someone point me to a relevant paper, or give a quick explanation?

Steinitz, Dominic J | 12 Mar 12:43 2001

Re: newbie

Monads in Haskell use the Kleisli triple definition which is equivalent to the two natural
transformations and functor definition (with the appropriate laws) - see Algebraic Theories by Manes.
When using the do notation you are effectively working in the Kleisli category generated by the monad.

Dominic.

edrx <at> inx.com.br on 10/03/2001 10:13:00
To:	haskell
cc:	
bcc:	Dominic Steinitz
Subject:	Re: newbie

Frank Atanassow wrote:
> G Murali wrote (on 09-03-01 00:43 +0000):
> > I'm new to this monads stuff.. can you tell me what it is simply ?
> > an example would be highly appreciated.. i want it is very very
> > simple terms please..
>
> A monad on category C is a monoid in the category of endofunctors on C.
>
> Is that simple enough? ;)
>
> No? Then see "Using Monads" at http://haskell.org/bookshelf/
>
> (Sorry, I just couldn't resist!)

Uh-oh.  I'm a junior categorist and toposopher and I confess that all
my few attempts to understand what Haskell's monads have to do with
the categorical notion of a monad have failed more or less miserably.
Can someone point me to a relevant paper, or give a quick explanation?

  Thanks in advance, and sorry for the dumb question,

    Eduardo Ochs
      http://angg.twu.net/
      edrx <at> inx.com.br

_______________________________________________
Haskell mailing list
Haskell <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell

-------------------------------------------------------------------------------------------------
21st century air travel     http://www.britishairways.com

Frank Atanassow | 9 Mar 21:33 2001
Picon

Re: newbie

> On Fri, 9 Mar 2001, Frank Atanassow wrote:
> > A monad on category C is a monoid in the category of endofunctors on C.

Surprisingly, my facetious little remark about monads elicited the following
response (whose author I will not disclose, as I haven't obtained
permission yet):

Somebody wrote (on 09-03-01 15:38 +0000):
> Hi Frank --- Believe it or not your one-liner actually *is* helpful to me.
> >From dim & distant algebra days I remember the definition of monoid (set,
> binary operation, associative, left & right unit) but being a Physics
> major/Maths minor, a long time ago, I was deprived of any introduction to
> Category Theory. I've read some of the papers Haskell monads section &
> also had a look at some category theory books --- but I can't remember
> seeing your nice one-line definition --- do you have a reference to the
> paper or book(s) that do it this way? 

I think the monoidal characterization is well known. I first saw it in Asperti
& Longo [1] (p.75), but I'm sure it can be found in other texts. The
connection with monoids is not very evident in Haskell, but is worth keeping
in mind if you know a bit of category theory.

BTW, part of the reason I'm posting this to the Haskell list is to plug a
little project I have started on my home page. It's a small collection of useful
reference texts which deal with programming languages and semantics, all of
which have become available on the web. [1] is among these.

<start violins for impassioned plea>

I occasionally see posts on this list from people who are not researchers or
educators (and consequently do not have ready access to such published
material) expressing some interest in exploring PL theory and other, related
formal topics further, if only the ``barrier-to-entry'' were not so
high. Indeed, there is a wealth of technical articles which are available
online, and could prove useful or at least interesting to many Haskell and ML
programmers, but even the ones directed at a relatively wide audience of PL
researchers can be hard to grasp for non-researchers. Personally, I think this
is one reason that Haskell and ML are still fairly marginalized languages. My
hope is that this list can grow into a useful resource for go-getters and
self-starters from other fields and communities, as well as the average PL
researcher.

<end violins for impassioned plea>

OK, I am only a stupid PhD student with no publications under my belt, but
anyhow that is how I felt before I became a researcher. Over the space of a
few years, while I was still hacking C++ in the dungeons of our vast corporate
megacomplex, I laid out several hundred dollars of my own money to buy enough
texts to jumpstart my own education, and what started with one book soon
exploded into a mini-library of hardbacks and articles (because you know the
dependencies in any non-trivial bibliography resemble a large bowl of sticky
spaghetti), and I would have been deliriously happy to learn that, for
example, Barendregt's encyclopaedic book on lambda-calculus was actually
readable from the web. So here's to you, my comrades-in-arms.

As it states on my page, if any of you know of any other relevant texts
which might be added to the list, please contact me and I will augment the
list forthwith.

The list is available at:

  http://www.cs.uu.nl/people/franka/

and here is the reference I promised:

  [1] Andrea Asperti and Giussepe Longo. Categories, Types and Structures. An
      introduction to Category Theory for the working computer
      scientist. MIT Press, 1991.
      URL: http://www.dmi.ens.fr/users/longo/download.html

Regards,
--

-- 
Frank Atanassow, Information & Computing Sciences, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-3261 Fax +31 (030) 251-379

Frank Atanassow | 12 Mar 15:10 2001
Picon

Re: newbie

Frank Atanassow wrote (on 09-03-01 21:33 +0100):
> > On Fri, 9 Mar 2001, Frank Atanassow wrote:
> > > A monad on category C is a monoid in the category of endofunctors on C.
> 
> Surprisingly, my facetious little remark about monads elicited the following
> response (whose author I will not disclose, as I haven't obtained
> permission yet):

So much for my attempt at discretion. Sorry, Phil. I Bcc'd the list, but maybe
my understanding of the way it works is wrong...

--

-- 
Frank Atanassow, Information & Computing Sciences, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-3261 Fax +31 (030) 251-379

Jens-Ulrik Petersen | 23 Mar 04:26 2001
Picon

url update for Asperti & Longo: "Categories, Types and Structures"

Hi Frank,

Thanks for making <http://www.cs.uu.nl/people/franka/ref.html>.  Good
idea!

"Frank Atanassow" <franka <at> cs.uu.nl> writes:

>   [1] Andrea Asperti and Giussepe Longo. Categories, Types and Structures. An
>       introduction to Category Theory for the working computer
>       scientist. MIT Press, 1991.
>       URL: http://www.dmi.ens.fr/users/longo/download.html

It seems ENS's DMI bifurcated... the current url is now

        http://www.di.ens.fr/users/longo/download.html

Maybe you could update the link on your page too.

Thanks, Jens


Gmane