
Hi guys, So one of the big things in object oriented programming is encapsulation, and I'm wondering how to do it properly in Haskell. How do you define new data types but minimize the dependence of external packages on the exact nature of the data definition?

On Thu, 22 Dec 2005, Creighton Hogg wrote:
Hi guys, So one of the big things in object oriented programming is encapsulation, and I'm wondering how to do it properly in Haskell. How do you define new data types but minimize the dependence of external packages on the exact nature of the data definition?
Use modules. Don't expose the constructors. -- flippa@flippac.org The task of the academic is not to scale great intellectual mountains, but to flatten them.

So one of the big things in object oriented programming is encapsulation, and I'm wondering how to do it properly in Haskell. How do you define new data types but minimize the dependence of external packages on the exact nature of the data definition? Use modules. Don't expose the constructors.
Instead, just expose functions that implement the functionality users of your library will need: http://www.haskell.org/hawiki/AbstractDataType http://www.haskell.org/hawiki/AbstractDataTypes Jared. -- jupdike@gmail.com http://www.updike.org/~jared/ reverse ")-:"

--- Philippa Cowderoy
On Thu, 22 Dec 2005, Creighton Hogg wrote:
Hi guys, So one of the big things in object oriented programming is encapsulation, and I'm wondering how to do it properly in Haskell. How do you define new data types but minimize the dependence of external packages on the exact nature of the data definition?
Use modules. Don't expose the constructors.
The trick, though, is that objects are stateful things. If you want to
program a binary search tree, then insertion ought to return an
entirely new tree, just as if objects were all immutable, and
operations on those objects simply creaqte new objects exactly like the
existing ones (except for the one change). I've thought about trying to
model this using monads and actions, but I'm not sure that's the best approach.
===
Gregory Woodhouse

On Thu, Dec 22, 2005 at 01:53:34PM -0800, Greg Woodhouse wrote:
The trick, though, is that objects are stateful things. If you want to program a binary search tree, then insertion ought to return an entirely new tree, just as if objects were all immutable, and operations on those objects simply creaqte new objects exactly like the existing ones (except for the one change). I've thought about trying to model this using monads and actions, but I'm not sure that's the best approach.
Use lexical closures. Initialize the state, variables, threads, etc, and then return (= expose) only the "methods", ie. monadic actions. Use the fact that both functions and IO actions are abstract (opaque?). Example: initObject = do var <- newVar let inc = do x <- readVar var writeVar var (x + 1) get = do readVar var return (inc, get) Best regards Tomasz -- I am searching for a programmer who is good at least in some of [Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland
participants (5)
-
Creighton Hogg
-
Greg Woodhouse
-
Jared Updike
-
Philippa Cowderoy
-
Tomasz Zielonka