Greg Fitzgerald | 27 Oct 21:23 2012
Picon

Overload function application? (was: foldr (.) id)

Should library functions target Control.Category?  We write for Num, IsString, and ListLike.  Haskell overloads number literals and string literals, and awkwardly not List literals.  Should Haskell overload function application too?

How cool would it be to be able to leverage all of Haskell's libraries, and effectively none of the runtime, by implementing instances for literals and function application?  Say, for example, to generate a call graph, or make the language strict, or target LLVM more directly.  Anyone tried this?

Thanks,
Greg


On Sat, Oct 27, 2012 at 11:39 AM, Greg Fitzgerald <garious <at> gmail.com> wrote:
> Alternatively: flip (foldr id)

Very cool, but...  

Prelude> import qualified Data.Foldable as F
Prelude F> :t F.foldr id
F.foldr id :: F.Foldable t => b -> t (b -> b) -> b


{- Generalizing -}

Prelude F> import qualified Control.Category as C
Prelude F C> :t F.foldr (C..) C.id
F.foldr (C..) C.id :: (F.Foldable t, C.Category cat) => t (cat b b) -> cat b b


{- Sneaky type-specialization -}

Prelude F C> :t F.foldr C.id
F.foldr C.id :: F.Foldable t => b -> t (b -> b) -> b


On Sat, Oct 27, 2012 at 3:09 AM, Ross Paterson <ross <at> soi.city.ac.uk> wrote:
On Fri, Oct 26, 2012 at 07:41:18PM +0100, Greg Fitzgerald wrote:
> I've recently found myself using the expression: "foldr (.) id" to
> compose a list (or Foldable) of functions.  It's especially useful
> when I need to map a function over the list before composing.  Does
> this function, or the more general "foldr fmap id", defined in a
> library anywhere?  I googled and hoogled, but no luck so far.

Alternatively: flip (foldr id)

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


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
wren ng thornton | 28 Oct 02:37 2012

Re: Overload function application? (was: foldr (.) id)

On 10/27/12 3:23 PM, Greg Fitzgerald wrote:
> Should library functions target Control.Category?  We write for Num,
> IsString, and ListLike.  Haskell overloads number literals and string
> literals, and awkwardly not List literals.  Should Haskell overload
> function application too?
>
> How cool would it be to be able to leverage all of Haskell's libraries, and
> effectively none of the runtime, by implementing instances for literals and
> function application?  Say, for example, to generate a call graph, or make
> the language strict, or target LLVM more directly.  Anyone tried this?

Categories, as such, don't have any notion of application. There's just 
the identity morphism and morphism composition.

Overloaded application is more the purview of Applicative, whence the 
name (<$>) as a generalization of ($).

--

-- 
Live well,
~wren

Gmane