In this program there is an interface IPoint and a function point (which acts as a class in c++) that implements the interface behaviour. I tried many methods to declare that the function point implements IPoint but could not do so.
{-# LANGUAGE EmptyDataDecls, TypeOperators, FlexibleContexts, FlexibleInstances,UndecidableInstances, MultiParamTypeClasses, ScopedTypeVariables, DeriveDataTypeable, TemplateHaskell #-}
{-# OPTIONS_GHC -fcontext-stack=100 #-}
module Point where
import OOHaskell
$(label "read'")
$(label "load")
$(label "incr")
type IPoint a =
Record ( Read' :=: IO a
:*: Load :=: (a-> IO())
:*: Incr :=: IO()
:*: HNil)
--point value self = self :: IO (IPoint a)
point value self
= do
valueRef <- newIORef value :: IO (IORef Integer)
returnIO $
read' .=. readIORef valueRef
.*. load .=. (\v -> writeIORef valueRef v)
.*. incr .=. modifyIORef valueRef (+1)
.*. emptyRecord
How can i specify that the function point implements IPoint??