Re: [Haskell-cafe] trouble installing ghc 6.6: xargs: /usr/bin/ar: terminated by signal 11

2007-02-20 Thread Thomas Hartman

I finally got around to trying this, but still no luck. now getting
missing cmm.h error.

[EMAIL PROTECTED]:~/haskellInstalls/ghc-6.6$ cat mk/build.mk
   SplitObjs=NO

after doing sudo make  make.out

[EMAIL PROTECTED]:~/haskellInstalls/ghc-6.6$ tail make.out


== make all -r;
in /home/thartman/haskellInstalls/ghc-6.6/rts

../compiler/ghc-inplace -H16m -O -optc-O2 -static -I. -#include
HCIncludes.h -fvia-C -dcmm-lint -c Apply.cmm -o Apply.o

Apply.cmm:13:17:  error: Cmm.h: No such file or directory
make[1]: *** [Apply.o] Error 1
make: *** [stage1] Error 1
[EMAIL PROTECTED]:~/haskellInstalls/ghc-6.6$

anyone seen this?

thanks, thomas.

2007/1/7, Duncan Coutts [EMAIL PROTECTED]:

On Sat, 2007-01-06 at 15:30 -0800, tphyahoo wrote:
 I'm having trouble installing ghc 6.6. On ubuntu, virtual server (user mode
 linux).

 Something seems to be killing the process, no idea why.

 Anyone seen this?

Yes.

 /usr/bin/ar: creating libHSbase.a
 xargs: /usr/bin/ar: terminated by signal 11


What is happening is that the ghc build system is linking thousands and
thousands of tiny .o files into libHSbase.a. GNU ar isn't optimised for
this use-case and it takes far more memory than it really needs to. So
what happens is that ar takes 500Mb of memory and your virtual
machine / virtual server probably isn't configured with that much memory
and so the linux kernel OOM killer terminates the ar process.

To make this worse, since there are so many .o files, it takes several
invocations of ar to link them all. On each invocation ar is building
the symbol index (-q is ignored) and this is what takes the most time
and memory. It's a good deal quicker to use a custom program (100 lines
of Haskell) to build libHSbase.a and then use ranlib just once to build
the symbol index.

I submitted a patch to gnu binutils to make ar take less memory when
linking 1000's of files so it now only takes around 100Mb rather than
500Mb when linking libHSbase.a. That patch is included in version 2.17 I
think (in other words most systems don't have it yet).

What you can do in the mean time is either configure your virtual
machine with more memory or turn off the split-objs feature when you
configure ghc. Just add SplitObjs=NO to your mk/build.mk file (which
may not exist to start with). (The Gentoo ebuild does this
automatically)

Duncan



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


[Haskell-cafe] Re: Genuine Eratosthenes sieve [Was: Optimization fun]

2007-02-20 Thread apfelmus
Yitzchak Gale wrote:

 Melissa O'Neill wrote:
- Eratosthenes's sieve never says the equivalent of, Hmm, I
 wonder if 19 is a multiple of 17 -- but both the basic sieve we
 began with and the deleteOrd version do
 
 So then maybe I taught my daughter the wrong thing.
 When she does 17, she moves ahead one number at
 a time. When she gets to a multiple of 17, she crosses
 it off. So yes, she does consider whether 19 is a multiple
 of 17.

Yes, thanks Yitzchak, that's exactly the point. In order to cross off a
number, one has to find it and then to cross it. The trouble comes from
the fact that both notions are somewhat interchangeable. In a sense,
'deleteOrd' searches all subsequent numbers to find the next one to
cross off. At the same time, it considers all subsequent numbers whether
they should be crossed off or not. Melissa's priority queue walks all
numbers and decides in O(log n) whether the scrutinee is the next number
to be crossed. It's the 'find' part that is algorithmically expensive.

The point about Eratosthenes's sieve is that it does not specify
algorithmically how to find the next number to be crossed. It does not
even define how to store (crossed) numbers, it stores them on paper.
Of course, the computer needs to know both and there is freedom of
interpretation how to implement it. But I'm glad that Melissa pointed
out that this implementation has to be chosen consciously.

So, I argue that Yitzchak's 'deleteOrd' is a genuine sieve of
Eratosthenes. The naive 'filter (\x - x `mod` p /= 0)' is it as well.
But I agree that the latter deserves more a name like transposed sieve
of Eratosthenes.

Regards,
apfelmus

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


Re[2]: [Haskell-cafe] ANNOUNCE: nobench: Haskell implementaion benchmarks. GHC v Hugs v Yhc v NHC v ...

2007-02-20 Thread Bulat Ziganshin
Hello Dougal,

Monday, February 19, 2007, 3:02:30 PM, you wrote:
 I suppose the ideal way to do it would be benchmarks for the (1) idiomatic
 and (2) the highly tuned implementations. Then the compiler writers can
 push 1 towards 2, while the pesky shootout implementers can move the
 goalposts of 2. ;-)

 In reality this may just foster a small set of horribly specialised
 optimisers in the compilers, with little benefit for real-world usage. :-(

i disagree. when i write some general-purpose library, i use these
optimization tricks to make library as fast as possible. and wide
audience of library users will benefit from such low-level
optimizations

great example of such low-level optimized library is ByteString which
provides C-close speed with very high-level interface



-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] return?

2007-02-20 Thread Bulat Ziganshin
Hello Vikrant,

Tuesday, February 20, 2007, 10:59:16 AM, you wrote:

 I encounter situation in which my function has to end recursion by
 doing nothing and otherwise keep calling same function with some
 different parameters. I did not find anything equivalent to pass
 or return statement in Haskell.

return ()

when (cond) $ do
  statements

unless (cond) $ do
  statements

if cond then statement else do
statements


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


[Haskell-cafe] newbie question about denotational semantics

2007-02-20 Thread Alexander Vodomerov
   Hi all!

I'm just started learning denotational semantics and have a simple question.

Suppose, we have simple language L (e.g. some form of lambda-calculus)
and have a semantic function: E : Term_L - Value.

Now, suppose, we extended our language with some additional side-effects
(e.g. state or continuations). For this purpose we first add new
syntactic construct to language (e.g 'call/cc'), and then write semantic
via monadic approach.

We have:

  L_ext = L + 'call/cc'

  E_ext : Term_{L_ext} - M (Value),

where M is some monad (Cont Value for our case).

Now, I want to proof statement that original and extended semantics are
coincide on expressions that don't use new constructs (call/cc). It
would be natural to formulate such theorem:

Theorem. If t is expression, that doesn't use new construct, then

E_orig(t) = E_ext(t).

Alas, this equation doesn't make any sense, because E_orig(t) and E_ext(t) are
elements of different domains: Value and M(Value).

The obvious fix it to use unit operation of monad (return in Haskell
syntax) to put both values into the same space. So we get:

Theorem (second try). For all t, bla-bla-bla..
   unit_M(E_orig(t)) = E_ext(t).

However, this still doesn't work because Values are in fact different:

-- in original semantic we have (more source code available below)
data Value1 = Number Int
| Func (Value1 - Value1)

-- in extended semantic we have  
data Value2 = Number Int
| Func (Value2 - M Value2)
  ^ note this M

The monad M seems to be wired in recursively in Value definition.

From the mathematical point of view it is common to use projection or
injection when one need to compare functions to different sets. However,
I don't see any obvious injection Value1 - Value2 or projection
Value2 - Value1.

Some monads can be removed, for example StateT can be eliminated with
runState with initial state and etc. However, some monads, for example
Error, Maybe, non-deteminism monad (powerdomain) don't have such
removal function. What is needed is general definition that can be
used for _any_ monad M.

The question is: how can this theorem be formulated (and prooved) in
mathematically precise way?

It seems that I missing something very trivial, so just reference to article
will be nice.

The more general question is: suppose original language already has
side-effects and was described using monad M_1. Now we add additional
effects and use bigger monad M_2. The same question arises: how one can
compare elements in Value domain defined via M_1 and M_2?

With best regards,
   Alexander.

PS. Some code I played with:

-- original semantic
import Control.Monad.Reader
import Control.Monad.State
import qualified Data.Map as Map

type Id = String
type Env = Map.Map String Value

stdops :: Map.Map String (Int - Int - Int)
stdops = Map.fromList [(+, (+)), (-, (-)), (*, (*))]

data Expr = Const Int
  | Var String
  | BinOp String Expr Expr
  | Lambda Id Expr
  | Appl Expr Expr deriving Show

data Value = Number Int
   | Func (Value - Value)
 
instance Show Value where
show (Number v) = show v
show (Func _) = *func*

eval :: Expr - Reader Env Value
eval (Const c) = return (Number c)
eval (Var i) = do
  env - ask
  return $ env Map.! i
eval (BinOp op x y) = do
  vx - eval x
  vy - eval y
  let opfun = stdops Map.! op
  case (vx, vy) of
(Number a, Number b) - return $ Number (opfun a b)
_ - error standard operation on not-numbers
eval (Lambda i expr) = do
  env - ask
  let f = \v - let newenv = Map.insert i v env in
runReader (eval expr) newenv
  return (Func f)
eval (Appl fun arg) = do
  vfun - eval fun
  varg - eval arg
  case vfun of
Func f - return $ f varg
_ - error application of not-function

do_eval :: Expr - Value
do_eval expr = runReader (eval expr) Map.empty

-- extended semanic
import Control.Monad.Reader
import Control.Monad.Cont
import qualified Data.Map as Map

type Id = String
type Env = Map.Map String Value
type M = Cont Value

stdops :: Map.Map String (Int - Int - Int)
stdops = Map.fromList [(+, (+)), (-, (-)), (*, (*))]

data Expr = Const Int
  | Var String
  | BinOp String Expr Expr
  | Lambda Id Expr
  | Appl Expr Expr
  | CallCC Expr deriving Show

data Value = Number Int
   | Func (Value - M Value)
 
instance Show Value where
show (Number v) = show v
show (Func _) = *func*

eval :: Expr - ReaderT Env M Value
eval (Const c) = return (Number c)
eval (Var i) = do
  env - ask
  return $ env Map.! i
eval (BinOp op x y) = do
  vx - eval x
  vy - eval y
  let opfun = stdops Map.! op
  case (vx, vy) of
(Number a, Number b) - return $ Number (opfun a b)
_ - error standard operation on not-numbers
eval (Lambda i expr) = do
  env - ask
  let f = \v - let newenv = Map.insert i v env in
runReaderT (eval expr) newenv
  return (Func f)
eval (Appl 

[Haskell-cafe] Map list of functions over a single argument

2007-02-20 Thread Paul Moore

I'm after a function, sort of equivalent to map, but rather than
mapping a function over a list of arguments, I want to map a list of
functions over the same argument. The signature would be [a - b] - a
- [b], but hoogle didn't come up with anything.

It seems like an obvious analogue of map, so I'm pretty sure I'm
missing something (otherwise, I'd just write it myself, and not bother
:-))

Can anyone point me in the right direction?

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


Re: [Haskell-cafe] Map list of functions over a single argument

2007-02-20 Thread Donald Bruce Stewart
p.f.moore:
 I'm after a function, sort of equivalent to map, but rather than
 mapping a function over a list of arguments, I want to map a list of
 functions over the same argument. The signature would be [a - b] - a
 - [b], but hoogle didn't come up with anything.

Prelude map ($ 3) [(*2),(+1),div 1]
[6,4,0]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Map list of functions over a single argument

2007-02-20 Thread Paul Moore

On 20/02/07, Donald Bruce Stewart [EMAIL PROTECTED] wrote:

p.f.moore:
 I'm after a function, sort of equivalent to map, but rather than
 mapping a function over a list of arguments, I want to map a list of
 functions over the same argument. The signature would be [a - b] - a
 - [b], but hoogle didn't come up with anything.

Prelude map ($ 3) [(*2),(+1),div 1]
[6,4,0]


Cool. I told you I was missing something! :-)

The more I learn about using higher order functions, the more impressed I get.

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


Re: [Haskell-cafe] Map list of functions over a single argument

2007-02-20 Thread Dougal Stanton
Quoth Paul Moore, nevermore,
 Prelude map ($ 3) [(*2),(+1),div 1]
 [6,4,0]
 
 Cool. I told you I was missing something! :-)

I suppose this would fit your original idea if you wanted that
particular type signature. (Warning: not tested.)

 f :: a - [a - b] - [b]
 f c fs = map ($ c) fs

 mapF :: [a - b] - a - [b]
 mapF = flip f

Aren't higher order functions just dreamy... ? ;-)

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


Re: [Haskell-cafe] Re: Genuine Eratosthenes sieve [Was: Optimizationfun]

2007-02-20 Thread Claus Reinke


i have to say that i find the folklore sieve quite acceptable as a sieve, whereas 
the faster test-against-primes is obviously different. but the discussion has 
prompted me to write yet another sieve, perhaps more acceptable to purists. 

instead of using (mod p) repeatedly and filtering directly, we zero out 
multiples of p, for all p, then filter out non-zero elements in a second phase:


   primes = 2 : filter (2) (foldr sieve id primes [0..])

   -- start sieve for p at position p*p, zeroing position off=(p-1)*(p-1)
   sieve p f xs@(off:_) = 0: tail (applyAt (p*p-off) (f . sieve' p) xs) 


   -- zero positions that are multiples of p
   sieve' p = applyAt p (\(_:b)-sieve' p (0:b))

   -- like splitAt, followed by (++), where only suffix is operated on
   -- infinite lists, non-negative offset
   applyAt 0 f xs = f xs
   applyAt n f (x:xs) = x:applyAt (n-1) f xs

it seems to be a lot faster than the folklore sieve, and within a factor of 2 
of the faster test-against-primes (given the repeated use of applyAt, I guess
it could be sped up further by using a piecewise contiguous list representation, 
aka polymorphic ByteString).


claus

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


[Haskell-cafe] Re: Genuine Eratosthenes sieve [Was: Optimization fun]

2007-02-20 Thread Jens Blanck


The point about Eratosthenes's sieve is that it does not specify
algorithmically how to find the next number to be crossed. It does not
even define how to store (crossed) numbers, it stores them on paper.



But , I believe that Eratosthenes's sieve does specify how to store numbers
and how to find the next to cross out.

This is how I remember it:

0 List the numbers from 2 onwards.
1 Take first uncrossed number, say p.
2 Cross every pth number from there on (crossed or not).
3 Repeat from 1.

That crossed or not appears above makes repeated filters very tricky. It
is trivial with a mutable array, but that is not the preferred way so one
needs to somehow merge the crossing out lists. I haven't looked at it
really, but being sorted lists I would have thought that this merger would
be easy without resorting to things like priority queues, could someone
point this out to me?

The above mayeasily be optimised to only listing odd numbers (still cross
out every pth number in the list), and much less importantly by starting
from whereever p*p is.

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


Re: [Haskell-cafe] newbie question about denotational semantics

2007-02-20 Thread Nicolas Frisby

I'm still getting my head around this myself, but I know a few
references that might help (maybe not directly, but they're in the
ballpark).

1 I believe the phrase natural lifting or naturality of liftings
is what you're after when you attempt to compare a monad and a bigger
monad that includes the affects of the first. I recall this concept
from Liang and Hudak's modular monadic semantics work, but I'm having
a heck of a time quickly finding it in their papers. Try at least
section 8.1 in Monad Transformers and Modular Interpreters.

2 Another example that helped me when getting a feel for reasoning
about monadic code (which is the basis of what we're doing here) was
William Harrison's Proof Abstraction for Imperative Languages
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell School of Expression

2007-02-20 Thread Andrew Wagner

Has anyone worked through HSOE lately? I'm wondering if I'm going to
be able to work through the examples that use their graphic library,
under gtk2hs on fedora. Is there a workaround for this?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] newbie question about denotational semantics

2007-02-20 Thread Nicolas Frisby

[my mail program hiccuped and chopped my message, sorry]

2 Another example that helped me when getting a feel for reasoning
about monadic code (which is the basis of what we're doing here) was
William Harrison's Proof Abstraction for Imperative Languages. It
uses monads and some of the notions like the ones you're in search of.

3 Lastly, we're reasoning about folds with denotational semantics.
Graham Hutton's Fold and Unfold for Program Semantics was a great
read for me. Using its techniques will likely shorten up any proof
we've got.

This is some of my favorite stuff, let me know how you fare with it!

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


Re: [Haskell-cafe] Map list of functions over a single argument

2007-02-20 Thread David Roundy
On Tue, Feb 20, 2007 at 02:07:08PM +, Paul Moore wrote:
 I'm after a function, sort of equivalent to map, but rather than
 mapping a function over a list of arguments, I want to map a list of
 functions over the same argument. The signature would be [a - b] - a
 - [b], but hoogle didn't come up with anything.
 
 It seems like an obvious analogue of map, so I'm pretty sure I'm
 missing something (otherwise, I'd just write it myself, and not bother
 :-))
 
 Can anyone point me in the right direction?

It's rather a small function to bother putting in the libraries, and I
think better expressed using map directly:

rmap fs x = map ($ x) fs
-- 
David Roundy
http://www.darcs.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Map list of functions over a single argument

2007-02-20 Thread Paul Moore

On 20/02/07, David Roundy [EMAIL PROTECTED] wrote:

It's rather a small function to bother putting in the libraries, and I
think better expressed using map directly:

rmap fs x = map ($ x) fs


Yes. Now that I know the idiom, there's clearly little point in having
a named function for it.

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


[Haskell-cafe] Re: speeding up fibonacci with memoizing

2007-02-20 Thread Jón Fairbairn
Thomas Hartman [EMAIL PROTECTED] writes:

- I just thought this was interesting, so I would share it.

- -- versus, try memoized_fibs !! 1
- memoized_fibs = map memoized_fib [1..]
- memoized_fib = ((map fib' [0 ..]) !!)
- where
-   fib' 0 = 0
-   fib' 1 = 1
-   fib' n = memoized_fib (n - 1) + memoized_fib (n - 2)

I can't let this thread go by without commenting that you
can do something a bit more general by providing a memoising
fixpoint operator that you can reuse for your other awkward
recursive functions:

 module MemoFib where

The unexciting version

 naive_fib 0 = 1
 naive_fib 1 = 1
 naive_fib n = naive_fib (n-1) + naive_fib (n-2)

The memoised version using a memoising fixpoint operator

 fibonacci
 = memoFix fib
   where fib fib 0 = 1
 fib fib 1 = 1
 fib fib n = fib (n-1) + fib (n-2)

I suppose if you want to put it in a library, you should
just put fib in, and allow the user to call memoFix fib to
make a new version when necessary?


A memoising fixpoint operator. It works by putting the
result of the first call of the function for each natural
number into a data structure and using that value for
subsequent calls ;-)

 memoFix f
  = mf 
where memo = fmap (f mf) (naturals 1 0)
  mf = (memo !!!)

A data structure with a node corresponding to each natural
number to use as a memo.

 data NaturalTree a = Node a (NaturalTree a) (NaturalTree a)

Map the nodes to the naturals in this order:

  0
1   2
   3 5 4 6
  7  ...

Look up the node for a particular number

 Node a tl tr !!! 0 = a 
 Node a tl tr !!! n | odd n = tl !!! top
| otherwise = tr !!! (top-1)
where top = n `div` 2

We surely want to ba able to map on these things...

 instance Functor NaturalTree where
fmap f (Node a tl tr) = Node (f a) (fmap f tl) (fmap f tr)

If only so that we can write cute, but inefficient things
like the below, which is just a NaturalTree such that
naturals!!!n == n:

  naturals = Node 0  (fmap ((+1).(*2)) naturals) (fmap ((*2).(+1)) naturals)

The following is probably more efficient (and, having
arguments won't hang around at top level, I think) -- have I
put more $!s than necessary?

 naturals r n = Node n ((naturals $! r2) $! (n+r))
   ((naturals $! r2) $! (n+r2))
where r2 = 2*r


Of course, if you want to take advantage of the pseudo O(n)
lookup time of arrays, you could use a NaturalTree of arrays
of some fixed size -- but arrays are O(log n) really...

-- 
Jón Fairbairn [EMAIL PROTECTED]

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


[Haskell-cafe] Re: Map list of functions over a single argument

2007-02-20 Thread apfelmus
Paul Moore wrote:
 I'm after a function, sort of equivalent to map, but rather than
 mapping a function over a list of arguments, I want to map a list of
 functions over the same argument. The signature would be [a - b] - a
 - [b], but hoogle didn't come up with anything.
 
 It seems like an obvious analogue of map, so I'm pretty sure I'm
 missing something (otherwise, I'd just write it myself, and not bother
 :-))
 
 Can anyone point me in the right direction?

It's also known as

  sequence :: Monad m = [m b] - m [b]

with m = (-) a

  sequence :: [a - b] - (a - [b])

This is the fabulous MonadReader.

Regards,
apfelmus

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


[Haskell-cafe] Re: Genuine Eratosthenes sieve [Was: Optimization fun]

2007-02-20 Thread apfelmus
Jens Blanck wrote:

 The point about Eratosthenes's sieve is that it does not specify
 algorithmically how to find the next number to be crossed. It does not
 even define how to store (crossed) numbers, it stores them on paper.
 
 But , I believe that Eratosthenes's sieve does specify how to store numbers
 and how to find the next to cross out.
 
 This is how I remember it:
 
 0 List the numbers from 2 onwards.
 1 Take first uncrossed number, say p.
 2 Cross every pth number from there on (crossed or not).
 3 Repeat from 1.

And where's the storage specification? :)

What I'd like to say is that in step 0, list the numbers may mean many
things to the computer. For example, it can list them in a plain list or
a finite map or a priority queue (or an array for the imperative).
Yitzchaks 'deleteOrd' sieve uses a plain list whereas Melissa stores the
crossed numbers in a priority queue. The choice has impact on how fast
you can find the next number to be crossed: Yitzchak needs linear time
whereas Melissa can do in logarithmic time. Here, time is parametrized
by the count of primes smaller than the current number considered.

In the end, the computer needs a more detailed description than the
human who can see and cross numbers on a piece of paper at his choice.

Regards,
apfelmus

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


Re: [Haskell-cafe] Re: Map list of functions over a single argument

2007-02-20 Thread David House

On 20/02/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

It's also known as

  sequence :: Monad m = [m b] - m [b]

with m = (-) a


Don't forget to import Control.Monad.Instances for this to work.

--
-David House, [EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Map list of functions over a single argument

2007-02-20 Thread Nicolas Frisby

Here comes an overwhelming post (so stop here if you're not interested
in applicative functors), but apfelmus stepped in this direction. The
funny part is that, modulo dictionary passing (which might be compiled
away), all 6 functions below do the Exact Same Thing because of
newtype erasure (Calling all experts: am I right about that?).

All of the themes below are explained in the Applicative Functors
pearl, which is an excellent read. See:
 http://lambda-the-ultimate.org/node/1137

The aha! this code attempts to illuminate is that the point that
'maps' can be written as the sequencing of the environment monad is
akin to saying that all regular polygons have a perimeter as opposed
to all 2-dimensional shapes have a perimeter. Both are obviously
legitimate claims, but we might be able to squeeze a little more
understanding out of the second version. A more germaine formulation:
it's not the monadic properties of the environment reader that we need
in order to solve this problem so much as it is the applicative
functor properties of the environment reader (which also happens to be
a monad).

Moreover, it doesn't just work for lists of functions--e.g. it could
work for trees too. The required property here is captured by
Data.Traversable, which the list type constructor satisfies. Use of
traversable often comes hand-in-hand with applicative functors.



\begin{code}
import qualified Control.Monad as M
import Control.Monad.Reader
import qualified Control.Applicative as AF
import qualified Data.Traversable as T

-- Nothing Fancy Here:
-- to avoid confusion with monad during this presentation,
-- we create a newtype for environment as an applicative functor
newtype ReaderAF r a = ReaderAF { runReaderAF :: r - a }
instance Functor (ReaderAF r) where
   fmap fn (ReaderAF f) = ReaderAF (fn . f)
instance AF.Applicative (ReaderAF r) where
   pure a = ReaderAF (const a)
   (ReaderAF f) * (ReaderAF g) = ReaderAF (\r - (f r) (g r))



-- our target functions
maps, mi_maps, me_maps, afe_maps, afi_maps, maf_maps :: [a - b] - a - [b]



-- conventional
maps fs a = map ($ a) fs

-- monadic (implicit reader)
mi_maps fs a = (M.sequence fs) a

-- monadic (explicit reader)
me_maps fs a = runReader (M.sequence fs') a
   where fs' = map Reader fs

-- applicative functor (explicit reader)
afe_maps fs a = runReaderAF (T.sequenceA fs') a
   where fs' = map ReaderAF fs

-- applicative functor (implicit reader)
afi_maps fs a = (T.sequenceA fs) a

-- combination (a monad as an applicative functor)
maf_maps fs a = runReader (AF.unwrapMonad (T.sequenceA fs')) a
   where fs' = map (AF.WrapMonad . Reader) fs
\end{code}


Also, Data.Traversable exports a function 'sequence' that generalizes
the one from Control.Monad/Prelude to work on more than just lists:

Prelude :m + Data.Traversable
Prelude Data.Traversable :t Data.Traversable.sequence
Data.Traversable.sequence :: (Traversable t, Monad m) = t (m a) - m (t a)

So we could have even written 4 more versions of the function that
again all reduce to the same thing (modulo dictionary passing)!

It isn't really highlighted above, but one high-level difference
between monads and applicative functors is a question of how paramount
is the notion of sequencing (the = kind of sequencing more so than
the 'sequence' kind of sequencing).

Sorry for the dropping the concept bomb on a simple question, but
hopefully someone enjoyed the adventure.

Nick

On 2/20/07, David House [EMAIL PROTECTED] wrote:

On 20/02/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 It's also known as

   sequence :: Monad m = [m b] - m [b]

 with m = (-) a

Don't forget to import Control.Monad.Instances for this to work.

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


[Haskell-cafe] Call for testers: using Cabal to build RPMs

2007-02-20 Thread Bryan O'Sullivan
I've got a branch of Cabal that adds a new command, rpm, that lets you 
build an RPM package with a single invocation:


  runhaskell Setup.*hs rpm

I've tested this pretty extensively with GHC 6.6, and I'm quite happy 
with it, but if there are other users of RPM-based distros out there, 
I'd appreciate it if you could kick the tyres a bit.


Once it's in solid shape, I hope to plug this capability into Hackage so 
that there will automatically be fresh RPM packages available for Linux 
distributions such as Fedora.


See the brief writeup here:

http://www.serpentine.com/blog/2007/02/20/haskell-cabal-now-with-extra-crunchy-rpm-goodness/

Cheers,

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


Re: [Haskell-cafe] Newbie: generating a truth table

2007-02-20 Thread Gene A

On 2/10/07, Peter Berry [EMAIL PROTECTED] wrote:


Sigh, I seem to have done a reply to sender. Reposting to the list.

On 06/02/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hello,

 I would like to create a Haskell function that generates a truth table,
for
 all Boolean values, say, using the following and function :

 and :: Bool - Bool - Bool
 and a b = a  b





This is solution that I used with list comprehension.. combining some of the
other ideas on the thread such as a tuple to see the original values and
then the result.

Prelude putStrLn $ concatMap (flip (++)\n) $ map show $ [(x,y,() x y)
|x - [True,False],y - [True,False]]
(True,True,True)
(True,False,False)
(False,True,False)
(False,False,False)

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


[Haskell-cafe] nobench: now with hbc support (!)

2007-02-20 Thread Donald Bruce Stewart
Just a quick note.

I've tweaked the benchmarks some more, adding support for Lennart's hbc
compiler. (Go hbc!). Also, we have nice html output (thanks to Text.XHtml!).

http://www.cse.unsw.edu.au/~dons/nobench/results.html

Pretty :-)

Remaining tasks left are to port the rest of the 'real' category from
nofib, and implement output diffing (note the nhc winning entries, due
to erroneous output), and add nhc's bytestring support.

The particular errors are logged here,

http://www.cse.unsw.edu.au/~dons/nobench/bench.results

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