{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE RankNTypes #-}

{-|
Module:      Control.Object
Copyright:   (C) 2015 The University of Kansas
License:     BSD-style (see the file LICENSE)
Maintainer:  Andy Gill
Stability:   Experimental

An Object type, which is a natural transformation into the 'IO' monad.
-}

module Control.Object (Object(..), (#)) where

import Control.Natural

-- | An 'Object' is a natural transformation from a given 'Functor' 'f', to 'IO'.
newtype Object f = Object (f ~> IO)

instance Transformation f IO (Object f) where
    Object forall a. f a -> IO a
f # :: Object f -> forall a. f a -> IO a
# f a
g = (forall a. f a -> IO a) -> f :~> IO
forall {k} (f :: k -> *) (g :: k -> *). (f ~> g) -> f :~> g
NT f x -> IO x
forall a. f a -> IO a
f (f :~> IO) -> forall a. f a -> IO a
forall {k} (f :: k -> *) (g :: k -> *) t.
Transformation f g t =>
t -> forall (a :: k). f a -> g a
# f a
g