Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fumieval/objective
Purely functional objects
https://github.com/fumieval/objective
Last synced: 26 days ago
JSON representation
Purely functional objects
- Host: GitHub
- URL: https://github.com/fumieval/objective
- Owner: fumieval
- License: bsd-3-clause
- Created: 2014-09-18T08:17:45.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-10-27T11:01:05.000Z (about 3 years ago)
- Last Synced: 2024-12-09T21:29:04.284Z (about 1 month ago)
- Language: Haskell
- Homepage:
- Size: 174 KB
- Stars: 73
- Watchers: 12
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
objective
====[![Hackage](https://img.shields.io/hackage/v/objective.svg)](https://hackage.haskell.org/package/objective) [![Build Status](https://secure.travis-ci.org/fumieval/objective.png?branch=master)](http://travis-ci.org/fumieval/objective)
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.
```haskell
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`.
```haskell
data Counter a where
Increment :: Counter ()
Print :: Counter Intcounter :: 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.
```haskell
> 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.