[Haskell-cafe] Object oriented haskell.
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
On May 15, 2014, 12:38:29 PM, silvio <silvio.frischi at gmail.com> wrote:
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 ]
fromList [('f',Just 1),('o',Nothing)]
> m . 'f'
> 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
Haskell-Cafe mailing list
mailto:Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe