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: Help with "20 intermediate haskell exercises"
(Daniel Fischer)
2. Re: help with types and composition (Troy Pracy)
3. Re: help with types and composition (Geoffrey Marchant)
4. Re: help with types and composition (Thomas Davie)
5. Re: GHC compiling for different platforms (Bernhard Lehnert)
----------------------------------------------------------------------
Message: 1
Date: Fri, 3 Jul 2009 18:08:30 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Help with "20 intermediate haskell
exercises"
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Freitag 03 Juli 2009 17:58:22 schrieb Patrick LeBoutillier:
> Hi,
>
> I'm running through these Haskell exercises:
>
>
> http://dibblego.wordpress.com/2008/09/18/20-intermediate-haskell-exercises/
>
> and I'm stuck at number 9:
>
>
> class Misty m where
> banana :: (a -> m b) -> m a -> m b
> unicorn :: a -> m a
>
> -- Exercise 9
> -- Relative Difficulty: 6
> instance Misty ((->) t) where
> banana = ???
> unicorn x = (\t -> x)
>
>
> I can picture it when m is "[]" or "Maybe", but I can't wrap my head
> around the banane implementation for "((->) t)".
> I can see that this somewhat looks like a Monad, with unicorn = return
> and banana = (flip >>=) or something. Perhaps some kind of reader
> Monad?
Exactly.
You want
banana :: (a -> (t -> b)) -> (t -> a) -> (t -> b)
banana fun af = \tval -> ???
There's not much choice what you can do with those types and data.
> Can anyone offer any insight?
>
>
> Patrick
------------------------------
Message: 2
Date: Sat, 4 Jul 2009 11:15:06 +1000
From: Troy Pracy <[email protected]>
Subject: Re: [Haskell-beginners] help with types and composition
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I've just started learning Haskell and I've been wondering about this issue
as well. I can usually work out a point-free version by carefullty deriving
it step-by-step, but I was wondering if Haskell had composition
operators/functions for dealing with the various forms of composition where
a 2-arg function is involved.
I've played around with J (APL's successor) a little and noticed that J has
various options for composing two functions (Ponit-free, or "implicit" style
is very important in J). Some of the distinctions have to do with J's
native array operations and aren't relevant here, but many are. Here are
Haskell versions...
(note: "monadic" below isn't used in the Haskell/CT sense - "monadic" and
"dyadic" in J jsut refer to how many arguments an operator acts on)
-- hook is the J dyadic hook as a function.
hook :: (a->b->c) -> (d->b) -> a -> d -> c
hook f g = \x y -> f x (g y)
-- J's monadic hook
mhook :: (a->b->c) -> (a->b) -> a -> c
mhook f g = \x -> (hook f g) x x
-- J's monadic fork
fork :: (a->b->c) -> (d->a) -> (d->b) -> d -> c
fork f g h = \x -> f (g x) (h x)
-- J's dyadic fork
dyfork :: (a->b->c) -> (d->e->a) -> (d->e->b) -> d -> e -> c
dyfork f g h = \x y -> f (g x y) (h x y)
-- J's dyadic @ or @: - composition of 1-arg fn with 2-arg fn
compose12 :: (a->b) -> (c->d->a) -> c -> d -> b
compose12 f g = \x y -> f (g x y)
(@:) = compose12
{- J's dyadic & or &: - composition of 2-arg fn with 1-arg fn, resulting in
a
2-arg fn (f&:g) which applies g to *both* args before passing them to f.
Haskell's composition operator and partial application allow a composition
of such fns (f . g) where g is applied only to the first arg. -}
compose21 :: (a->a->b) -> (c->a) -> c -> c -> b
compose21 f g = \x y -> f (g x) (g y)
(&:) = compose21
/ /I know a lot of Haskell is written in point-free style and I would have
thought Haskell would have operators for some of this, but judging from the
previous responses, it looks like it might not. That surprises me, since
some of this seems to crop up a lot, but as I said I've just started
learning Haskell, so I guess I'll have to give myself some time to absorb
the Haskell way of doing things.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090703/2179c1d6/attachment-0001.html
------------------------------
Message: 3
Date: Sat, 4 Jul 2009 03:15:27 -0600
From: Geoffrey Marchant <[email protected]>
Subject: Re: [Haskell-beginners] help with types and composition
To: Troy Pracy <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Functions in Haskell aren't distinguished as 1-arg of 2-arg functions.
Usually we don't even think of them as such -- rather we think of the type
of the function or operator.
But there is a wide array of combinators available:
K = const
I = id
B = (.)
C = flip
S = Monad.ap -- instance Monad (->) a - the Reader Monad
W = Monad.join -- also for the Reader Monad
Y = Control.Monad.Fix.fix
and the list goes on and on... Using only S and K, a great many functions
can be expressed, though it does get rather ugly.
Perhaps the most significant reason that Haskell doesn't have more
composition operators is that composing functions is the least part of what
we compose. Using some standard class functions often yields exactly what
you're looking for:
hook = liftM2 (.)
mhook = ap
fork = liftM2
dyfork = liftM2 . liftM2
compose12 = (.) (.) (.) -- as previously shown
Written in this form, the first four become far more general:
"hook" is function composition within a monad;
"mhook" is function application within a monad;
"fork" raises a function for application on monads; and
"dyfork" -- absolutely beautiful, BTW -- raises a function for application
upon nested monads.
BTW, if anyone has a reasonably concise form for a point-free compose21, I'd
like to see it.
On Fri, Jul 3, 2009 at 7:15 PM, Troy Pracy <[email protected]> wrote:
> I've just started learning Haskell and I've been wondering about this issue
> as well. I can usually work out a point-free version by carefullty deriving
> it step-by-step, but I was wondering if Haskell had composition
> operators/functions for dealing with the various forms of composition where
> a 2-arg function is involved.
>
> I've played around with J (APL's successor) a little and noticed that J has
> various options for composing two functions (Ponit-free, or "implicit" style
> is very important in J). Some of the distinctions have to do with J's
> native array operations and aren't relevant here, but many are. Here are
> Haskell versions...
> (note: "monadic" below isn't used in the Haskell/CT sense - "monadic" and
> "dyadic" in J jsut refer to how many arguments an operator acts on)
>
> -- hook is the J dyadic hook as a function.
> hook :: (a->b->c) -> (d->b) -> a -> d -> c
> hook f g = \x y -> f x (g y)
> -- J's monadic hook
> mhook :: (a->b->c) -> (a->b) -> a -> c
> mhook f g = \x -> (hook f g) x x
> -- J's monadic fork
> fork :: (a->b->c) -> (d->a) -> (d->b) -> d -> c
> fork f g h = \x -> f (g x) (h x)
> -- J's dyadic fork
> dyfork :: (a->b->c) -> (d->e->a) -> (d->e->b) -> d -> e -> c
> dyfork f g h = \x y -> f (g x y) (h x y)
> -- J's dyadic @ or @: - composition of 1-arg fn with 2-arg fn
> compose12 :: (a->b) -> (c->d->a) -> c -> d -> b
> compose12 f g = \x y -> f (g x y)
> (@:) = compose12
> {- J's dyadic & or &: - composition of 2-arg fn with 1-arg fn, resulting
> in a
> 2-arg fn (f&:g) which applies g to *both* args before passing them to f.
> Haskell's composition operator and partial application allow a
> composition
> of such fns (f . g) where g is applied only to the first arg. -}
> compose21 :: (a->a->b) -> (c->a) -> c -> c -> b
> compose21 f g = \x y -> f (g x) (g y)
> (&:) = compose21
>
>
> / /I know a lot of Haskell is written in point-free style and I would have
> thought Haskell would have operators for some of this, but judging from the
> previous responses, it looks like it might not. That surprises me, since
> some of this seems to crop up a lot, but as I said I've just started
> learning Haskell, so I guess I'll have to give myself some time to absorb
> the Haskell way of doing things.
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090704/69375793/attachment-0001.html
------------------------------
Message: 4
Date: Sat, 4 Jul 2009 12:33:24 +0200
From: Thomas Davie <[email protected]>
Subject: Re: [Haskell-beginners] help with types and composition
To: Geoffrey Marchant <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
Note here that where liftM2 and ap are used, we can be more general
than monads -- we need only Applicatives instead, substituting liftA2
and <*> instead.
Also, compose12 can be made more general using (fmap . fmap), and
becomes the two level fmap -- instead of applying the function inside
one layer of functor it goes two layers in. Similarly with hook, we
can use liftA2 fmap, and be generalised over all functors, not just
functions.
Bob
On 4 Jul 2009, at 11:15, Geoffrey Marchant wrote:
> Functions in Haskell aren't distinguished as 1-arg of 2-arg
> functions. Usually we don't even think of them as such -- rather we
> think of the type of the function or operator.
>
> But there is a wide array of combinators available:
>
> K = const
> I = id
> B = (.)
> C = flip
> S = Monad.ap -- instance Monad (->) a - the Reader Monad
> W = Monad.join -- also for the Reader Monad
> Y = Control.Monad.Fix.fix
>
> and the list goes on and on... Using only S and K, a great many
> functions can be expressed, though it does get rather ugly.
>
> Perhaps the most significant reason that Haskell doesn't have more
> composition operators is that composing functions is the least part
> of what we compose. Using some standard class functions often yields
> exactly what you're looking for:
>
> hook = liftM2 (.)
> mhook = ap
> fork = liftM2
> dyfork = liftM2 . liftM2
> compose12 = (.) (.) (.) -- as previously shown
>
> Written in this form, the first four become far more general:
>
> "hook" is function composition within a monad;
> "mhook" is function application within a monad;
> "fork" raises a function for application on monads; and
> "dyfork" -- absolutely beautiful, BTW -- raises a function for
> application upon nested monads.
>
> BTW, if anyone has a reasonably concise form for a point-free
> compose21, I'd like to see it.
>
>
> On Fri, Jul 3, 2009 at 7:15 PM, Troy Pracy <[email protected]> wrote:
> I've just started learning Haskell and I've been wondering about
> this issue as well. I can usually work out a point-free version by
> carefullty deriving it step-by-step, but I was wondering if Haskell
> had composition operators/functions for dealing with the various
> forms of composition where a 2-arg function is involved.
>
> I've played around with J (APL's successor) a little and noticed
> that J has various options for composing two functions (Ponit-free,
> or "implicit" style is very important in J). Some of the
> distinctions have to do with J's native array operations and aren't
> relevant here, but many are. Here are Haskell versions...
> (note: "monadic" below isn't used in the Haskell/CT sense -
> "monadic" and "dyadic" in J jsut refer to how many arguments an
> operator acts on)
>
> -- hook is the J dyadic hook as a function.
> hook :: (a->b->c) -> (d->b) -> a -> d -> c
> hook f g = \x y -> f x (g y)
> -- J's monadic hook
> mhook :: (a->b->c) -> (a->b) -> a -> c
> mhook f g = \x -> (hook f g) x x
> -- J's monadic fork
> fork :: (a->b->c) -> (d->a) -> (d->b) -> d -> c
> fork f g h = \x -> f (g x) (h x)
> -- J's dyadic fork
> dyfork :: (a->b->c) -> (d->e->a) -> (d->e->b) -> d -> e -> c
> dyfork f g h = \x y -> f (g x y) (h x y)
> -- J's dyadic @ or @: - composition of 1-arg fn with 2-arg fn
> compose12 :: (a->b) -> (c->d->a) -> c -> d -> b
> compose12 f g = \x y -> f (g x y)
> (@:) = compose12
> {- J's dyadic & or &: - composition of 2-arg fn with 1-arg fn,
> resulting in a
> 2-arg fn (f&:g) which applies g to *both* args before passing them
> to f.
> Haskell's composition operator and partial application allow a
> composition
> of such fns (f . g) where g is applied only to the first arg. -}
> compose21 :: (a->a->b) -> (c->a) -> c -> c -> b
> compose21 f g = \x y -> f (g x) (g y)
> (&:) = compose21
>
>
> / /I know a lot of Haskell is written in point-free style and I
> would have thought Haskell would have operators for some of this,
> but judging from the previous responses, it looks like it might not.
> That surprises me, since some of this seems to crop up a lot, but as
> I said I've just started learning Haskell, so I guess I'll have to
> give myself some time to absorb the Haskell way of doing things.
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 5
Date: Sat, 04 Jul 2009 14:04:11 +0200
From: Bernhard Lehnert <[email protected]>
Subject: Re: [Haskell-beginners] GHC compiling for different platforms
To: Sean Bartell <[email protected]>
Cc: Magnus Therning <[email protected]>, [email protected]
Message-ID: <1246709051.11684.1.ca...@sol>
Content-Type: text/plain
Thanks for all the help. I'lll first try to just use the 32-bit
precompiled version and will google about the other answers.
Thanks to all,
Bernhard
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 13, Issue 3
****************************************