Re: [Haskell-cafe] N and R are categories, no?

2007-03-15 Thread Ulf Norell

On 3/15/07, Steve Downey [EMAIL PROTECTED] wrote:


EOk, i'm trying to write down, not another monad tutorial, because I
don't know that much yet, but an explication of my current
understanding of monads.

But before I write down something that is just flat worng, I thought
I'd get a cross check. (and I can't get to #haskell)

Monads are Functors. Functors are projections from one category to
another such that structure is preserved. One example I have in mind
is the embedding of the natural numbers into the real numbers. The
mapping is so good, that we don't flinch at saying 1 == 1.0.



Monads are endofunctors (functors from one category to itself). This is easy
to see from the type of join:

join : m (m a) - m a

For Haskell monads the category is the category of Haskell types and Haskell
functions. In this category N and R are objects, so you'll get the wrong
idea trying to see them as categories.

/ Ulf
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Logic programming using lazy evaluation

2007-02-27 Thread Ulf Norell

On 2/27/07, Henning Thielemann [EMAIL PROTECTED] wrote:


I suspect that someone has already done this: A Haskell library which
solves a system of simple equations, where it is only necessary to derive
a value from an equation where all but one variables are determined. Say


You might want to check out the following paper:

http://www.cs.chalmers.se/~koen/pubs/entry-haskell00-typedlp.html

/ Ulf
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Happy outputs parE - ideas on what to change in my .y file?

2007-01-29 Thread Ulf Norell


On Jan 27, 2007, at 11:11 AM, Mark Wassell wrote:

Sometimes happy outputs 'parE' when I run it on my .y file? I  
believe it is coming from a part of Grammer.lhs which has the  
comment line


This bit is a real mess, mainly because of the error message  
support.


Are there any suggestions on what to change in my .y file to get  
over this?


I've run into this problem as well (and submitted a bug report). You  
get the problem when there are undefined productions in your grammar.  
For instance:


%name parser Foo
%%
Foo : Bar { () }

/ Ulf
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Article review: Category Theory

2007-01-19 Thread Ulf Norell


On Jan 18, 2007, at 10:09 PM, Yitzchak Gale wrote:


I wrote:

Will (id :: A - A $!) do the trick?


Ulf Norell wrote:

The problem is not with id, it's with composition. For any f and g we
have

f . g = \x - f (g x)

So _|_ . g = \x - _|_ for any g.


OK, so then how about

f .! g = ((.) $! f) $! g


That should probably do the trick.

/ Ulf
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Article review: Category Theory

2007-01-19 Thread Ulf Norell


On Jan 19, 2007, at 1:06 PM, Yitzchak Gale wrote:


Hmm. I wrote:


for simplicity, we will ignore these distinctions


But do we really want to do that? Are the monads
that we use every day in Haskell really monads
if we check the axioms using (.!) instead of (.)
as we should? I'm not so sure anymore...


Personally I think that the distinction between _|_ and \x - _|_ is  
a mistake and should be ignored whenever possible.


/ Ulf
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Article review: Category Theory

2007-01-18 Thread Ulf Norell


On Jan 16, 2007, at 7:22 PM, David House wrote:


Hey all,

I've written a chapter for the Wikibook that attempts to teach some
basic Category Theory in a Haskell hacker-friendly fashion.

http://en.wikibooks.org/wiki/Haskell/Category_theory


In the section on the category laws you say that the identity  
morphism should satisfy


  f . idA = idB . f

This is not strong enough. You need

  f . idA = f = idB . f

Unfortunately, fixing this means that the category Hask is no longer  
a category since


  _|_ . id = \x - _|_ ≠ _|_

Also it's a bit strange to state that morphisms are closed under  
composition after the associativity law. Wouldn't it be nicer to  
introduce composition as a total operation off the bat?


/ Ulf

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Reversing a string of words: C# v Perl V Ruby v Haskell

2006-12-13 Thread Ulf Norell


On Dec 13, 2006, at 3:54 AM, Yitz Gale wrote:


Nice. Here is something similar:

reverseWords = concat . reverse . groupBy eqsp
  where eqsp x y = isSpace x == isSpace y


This can be made even nicer using the 'on' function [1]:

reverseWords = concat . reverse . groupBy ((==) `on` isSpace)

[1] http://www.haskell.org/pipermail/libraries/2006-November/006156.html

/ Ulf



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simple GADT parser for the eval example

2006-10-31 Thread Ulf Norell


On Oct 31, 2006, at 2:19 AM, Dimitrios Vytiniotis wrote:


-- Give a GADT for representation types
data R a where
  Rint :: R Int
  Rbool :: R Bool
  Rpair :: R a - R b - R (a,b)

-- Give an existential type with a type representation
data TermEx where
  MkTerm :: R a - Term a - TermEx

-- we use Weirich's higher-order type-safe cast to avoid deep  
traversals

-- one can replace the type_cast with a more simple traversal-based
-- version.


...complicated higher order stuff...

For instance:

 data a :==: b where
   Refl :: a :==: a

 (===) :: Monad m = R a - R b - m (a :==: b)
 Rint  === Rint  = return Refl
 Rbool  === Rbool = return Refl
 Rpair a b === Rpair c d = do
 Refl - a === c
 Refl - b === d
 return Refl
 a === b = fail $ show a ++  =/=  ++ show b

 cast :: a :==: b - c a - c b
 cast Refl x = x

In particular one wants to extract the Term part of a TermEx:

 getTerm :: Monad m = TermEx - R a - m (Term a)
 getTerm (MkTerm r' t) r = do
   Refl - r === r'
   return t

/ Ulf

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Last statement in 'do' must be an expression error.

2006-08-17 Thread Ulf Norell


On Aug 17, 2006, at 10:18 AM, Szymon Ząbkiewicz wrote:


Hi.

When trying to compilke this code:

{...}
8.if (a == 0)  (b == 0)
9.   then do
10. nr1 - read (prompt enter 1. number: )
11. nr2 - read (prompt enter 2. number: )
12.   else do
13.let nr1 = a
14.nr2 = b
{...}

The compiler tells me thats there's an error on line 10:
The last statement in a 'do' construct mesy be an expression

Could you tell me how to change it so that the declaration of the
first nr1 and nr2 is still in the then block.


The problem is that variables defined in the branch of an if are  
local to the branch. If you want to use them outside you have to  
return them from the branch:


do
  (nr1, nr2) -
if (a == 0)  (b == 0)
then do
   nr1 - read (prompt enter 1. number: )
   nr2 - read (prompt enter 2. number: )
   return (nr1, nr2)
else do
   let nr1 = a
   nr2 = b
   return (nr1, nr2)

/ Ulf___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe