objective: Composable objects

[ bsd3, control, library ] [ Propose Tags ]

Composable objects


[Skip to Readme]
Versions [faq] 0.0, 0.0.1, 0.0.2, 0.1, 0.2, 0.3, 0.4, 0.5, 0.5.1, 0.5.2, 0.5.2.1, 0.6, 0.6.1, 0.6.2, 0.6.3, 0.6.3.2, 0.6.3.3, 0.6.5, 0.6.5.1, 1, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1, 1.1.1, 1.1.2, 1.2 (info)
Change log CHANGELOG.md
Dependencies base (>=4.6 && <5), bifunctors, containers (>=0.5.0.0 && <0.6), exceptions (>=0.8), hashable, monad-skeleton (>=0.1.1 && <0.3), mtl, profunctors, template-haskell, transformers (>=0.3 && <0.6), transformers-compat, unordered-containers (>=0.2.0.0 && <0.3), void, witherable (>=0.1.3) [details]
License BSD-3-Clause
Copyright Copyright (c) 2014 Fumiaki Kinoshita
Author Fumiaki Kinoshita
Maintainer Fumiaki Kinoshita <fumiexcel@gmail.com>
Category Control
Home page https://github.com/fumieval/objective
Bug tracker http://github.com/fumieval/objective/issues
Source repo head: git clone https://github.com/fumieval/objective.git
Uploaded by FumiakiKinoshita at 2020-03-12T01:03:37Z
Distributions NixOS:1.2
Downloads 18134 total (66 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2020-03-12 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for objective-1.2

[back to package description]

objective

Hackage Build Status

Paper: https://fumieval.github.io/papers/en/2015-Haskell-objects.html

This package provides composable objects and instances.

Introduction

The primal construct, Object, models object-oriented objects. Object f g represents an object.

newtype Object f g = Object { runObject :: forall x. f x -> g (x, Object f g) }

An object interprets a message f a and returns the result a and the next object Object f g, on g.

data Counter a where
  Increment :: Counter ()
  Print :: Counter Int

counter :: Int -> Object Counter IO
counter n = Object $ \case
  Increment -> return ((), counter (n + 1))
  Print -> print n >> return (n, counter n)

new :: Object f g -> IO (Instance f g) creates an instance of an object.

(.-) :: (MonadIO m, MonadMask m) => Instance f m -> f a -> m a sends a message to an instance. This can be used to handle instances in the typical OOP fashion.

> i <- new (counter 0)
> i .- Increment
> i .- Print
1
> i .- Increment
> i .- Print
2

Interestingly, Object (Skeleton t) m and Object t m are isomorphic (Skeleton is an operational monad). cascading lets objects to handle an operational monad.