Beginners Digest, Vol 56, Issue 18

2013-02-10 Thread beginners-request
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.  Type of a Group. (Robert Goss)
   2. Re:  Type of a Group. (Rustom Mody)
   3. Re:  Type of a Group. (Robert Goss)


--

Message: 1
Date: Sat, 09 Feb 2013 13:05:12 +
From: Robert Goss 
Subject: [Haskell-beginners] Type of a Group.
To: beginners@haskell.org
Message-ID: <51164988.1050...@gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Dear all,

Looking to learn a little haskell I tried to program up a little group 
theory but feel I am stuck on what the types should be. At first it 
seemed obvious (and the algebra package does this) that the type of a 
group should be given by:

class Group g where
   mul :: g -> g -> g
   inv :: g -> g
   unit :: g

My problem is this seems to assume that the type of group you are in is 
encoded by the type system.

I first ran into problems with this when I wanted to define a cyclic 
group. The only way I could define the type was either to define each 
cyclic group separately so have C2, C3, C4, ... or parametrise it over 
the class Nat. So a cyclic group would have the type Cyclic (Succ(Succ( 
... Succ(Zero)) ... )) which would consistently define all cyclic groups 
but is hardly any better. For example a computation mod a large prime p 
is not going to be pleasant.

I came up with a partial solution by realising that a group is defined 
as a set X and some operations on it to get

class Group g x where
   mul :: g -> x -> x -> x
   inv :: g-> x -> x
   unit :: g -> x

Making it easy to define cyclic groups and all my old groups carry over. 
But now to evaluate an expression I need to hang onto the group i am in 
and pass it around. As i am newish to haskell I wanted to know if I have 
missed a simpler more obvious way of doing things?

All the best,

Robert Goss




--

Message: 2
Date: Sat, 9 Feb 2013 22:29:37 +0530
From: Rustom Mody 
Subject: Re: [Haskell-beginners] Type of a Group.
To: beginners@haskell.org
Message-ID:

Content-Type: text/plain; charset="iso-8859-1"

On Sat, Feb 9, 2013 at 6:35 PM, Robert Goss  wrote:

> Dear all,
>
> Looking to learn a little haskell I tried to program up a little group
> theory but feel I am stuck on what the types should be. At first it seemed
> obvious (and the algebra package does this) that the type of a group should
> be given by:
>
> class Group g where
>   mul :: g -> g -> g
>   inv :: g -> g
>   unit :: g
>
> My problem is this seems to assume that the type of group you are in is
> encoded by the type system.
>
> I first ran into problems with this when I wanted to define a cyclic
> group. The only way I could define the type was either to define each
> cyclic group separately so have C2, C3, C4, ... or parametrise it over the
> class Nat. So a cyclic group would have the type Cyclic (Succ(Succ( ...
> Succ(Zero)) ... )) which would consistently define all cyclic groups but is
> hardly any better. For example a computation mod a large prime p is not
> going to be pleasant.
>
> I came up with a partial solution by realising that a group is defined as
> a set X and some operations on it to get
>
> class Group g x where
>   mul :: g -> x -> x -> x
>   inv :: g-> x -> x
>   unit :: g -> x
>
> Making it easy to define cyclic groups and all my old groups carry over.
> But now to evaluate an expression I need to hang onto the group i am in and
> pass it around. As i am newish to haskell I wanted to know if I have missed
> a simpler more obvious way of doing things?
>
> All the best,
>
> Robert Goss
>
>
Taking your first approach I could do this much:

---
class Group g where
  mul :: g -> g -> g
  inv :: g -> g
  unit :: g

class Group g => CycGroup g where
  gen :: g

class CycGroup g => FiniteCycGroup g where
  baseSet :: [g]

-- I would have preferred to have order :: Int, to baseSet
-- but ghc does not like that for some reason


data G2 = A|B

instance Group G2 where
  unit = A

  inv A = A
  inv B = B

  mul A A = A
  mul A B = B
  mul B A = B
  mul B B = A

instance CycGroup G2 where
  gen = B

instance FiniteCycGroup G2  where
  baseSet = [A, B]
--




-- 
http://www.the-magus.in
http://blog.languager.org
-- next part --
An HTML attachment was scrubbed...
URL: 



Beginners Digest, Vol 56, Issue 19

2013-02-10 Thread beginners-request
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.  Haskell and Category Theory (Patrick Lynch)
   2. Re:  Haskell and Category Theory (KC)
   3. Re:  Haskell and Category Theory (amin...@gmail.com)
   4. Re:  Haskell and Category Theory (KC)
   5.  Effective use of nested Monads (David Hinkes)
   6. Re:  Effective use of nested Monads (Ozgur Akgun)
   7. Re:  Haskell and Category Theory (Brent Yorgey)
   8. Re:  Effective use of nested Monads (Brent Yorgey)


--

Message: 1
Date: Sun, 10 Feb 2013 12:44:11 -0500
From: "Patrick Lynch" 
Subject: [Haskell-beginners] Haskell and Category Theory
To: 
Message-ID: 
Content-Type: text/plain; charset="iso-8859-1"

Good morning,
I've tried to read 5 books on Category Theory and finally have admitted defeat.
What I'm looking for is simply a book that is geared to Haskell and Category 
that can be understood by mere mortals.
I was trained as an Electrical Engineer, so my math is quite good, but I just 
don't get Category Theory from these books.
If anyone can recomment a book on Category Theory and Haskell, written by a 
Computer Scientest [no more Mathematicians for me], I welcome it.
Thanks,
Patrick
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130210/8f36a6de/attachment-0001.htm>

--

Message: 2
Date: Sun, 10 Feb 2013 09:58:18 -0800
From: KC 
Subject: Re: [Haskell-beginners] Haskell and Category Theory
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Message-ID:

Content-Type: text/plain; charset=ISO-8859-1

Category Theory turns function like entities (e.g. procedures -
functions with side effects) into functions so that they can be
composed like mathematical functions.


On Sun, Feb 10, 2013 at 9:44 AM, Patrick Lynch  wrote:
> Good morning,
> I've tried to read 5 books on Category Theory and finally have admitted
> defeat.
> What I'm looking for is simply a book that is geared to Haskell and Category
> that can be understood by mere mortals.
> I was trained as an Electrical Engineer, so my math is quite good, but I
> just don't get Category Theory from these books.
> If anyone can recomment a book on Category Theory and Haskell, written by a
> Computer Scientest [no more Mathematicians for me], I welcome it.
> Thanks,
> Patrick
>
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
--
Regards,
KC



--

Message: 3
Date: Sun, 10 Feb 2013 13:49:28 -0500
From: amin...@gmail.com
Subject: Re: [Haskell-beginners] Haskell and Category Theory
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell 
Cc: "" 
Message-ID: <4722d1d6-fc2c-4712-aa62-86b6469bb...@gmail.com>
Content-Type: text/plain; charset="us-ascii"

I'm a fan of Basic Category Theory for Computer Scientists, by Benjamin Pierce.

I can't say it had an immediate payoff for learning Haskell, but it's been 
helpful longer-term.

Tom


On Feb 10, 2013, at 12:44 PM, "Patrick Lynch"  wrote:

> Good morning,
> I've tried to read 5 books on Category Theory and finally have admitted 
> defeat.
> What I'm looking for is simply a book that is  geared to Haskell and Category 
> that can be understood by mere mortals.
> I was trained as an Electrical Engineer, so my math is quite good, but I just 
> don't get Category Theory from these books.
> If anyone can recomment a book on Category Theory and Haskell, written by a 
> Computer Scientest [no more Mathematicians for me], I welcome it.
> Thanks,
> Patrick
> ___
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
-- next part --
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130210/be484d35/attachment-0001.htm>

--

Message: 4
Date: Sun, 10 Feb 2013 11:46:42 -0800
From: KC 
Subject: Re: [Haskell-beginners] Haskell and Category