[Haskell-cafe] Object oriented haskell.

Kyle Marek-Spartz kyle.marek.spartz at gmail.com
Thu May 15 17:44:32 UTC 2014

Recently, on LtU: http://lambda-the-ultimate.org/node/4951  

Most relevantly: https://ghc.haskell.org/trac/ghc/wiki/Records/DeclaredOverloadedRecordFields/DotPostfix

Kyle Marek-Spartz

On May 15, 2014, 12:38:29 PM, silvio <silvio.frischi at gmail.com> wrote:  

Hi Haskell,

I've been wondering if (.) is so cool in other languages why can't we
make it even cooler in haskell. And went on to implement such a (.)
based on multiparameter type classes and type families.

type family Output object action
class Action object action where
(.) :: object -> action -> Output object action

I'm not sure if this has been done before like this but i didn't find
I used Map as an example, and here is what I ended up with:

> :m -Prelude
> import Prelude hiding ((.))
> import Object
> import Object.Example
> import Data.Map hiding (size)
> let m = empty . [ 'f' := Just 1, 'o' := Just 2, 'o' := Nothing ]
> m
fromList [('f',Just 1),('o',Nothing)]
> m . 'f'
Just 1
> m . size

I also have a pretty cool (almost) solution to the name collision problem.

Visit the project homepage for a more thorough explanation.


And to those who gonna hate on me because they like the (.) as function
composition I have only this to say.

type instance Output (b -> c) (a -> b') = (a -> c)
instance (b ~ b') => Action (b -> c) (a -> b') where
f . g = f Prelude.. g

Have fun,

Haskell-Cafe mailing list
mailto:Haskell-Cafe at haskell.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140515/6a0d8ae0/attachment.html>

More information about the Haskell-Cafe mailing list