[Haskell-cafe] Can subclass override its super-class' default implementation of a function?

Donn Cave donn at avvanta.com
Mon Apr 27 18:56:37 EDT 2009


Quoth siki <gabor at karamaan.com>,

> The actual problem is quite similar to the one that I provided or to the one
> in the description of the proposed extension that you linked. 
>
> Someone on another forum suggested record functions but I'm not sure I
> understood correctly how that would work around this problem. Any suggestion
> is greatly appreciated!

Maybe it was function records.  That's kind of the poor man's OOP in
Haskell - no typeclasses needed.

data FileRec = FileRec {
	  fileRecRead :: Int -> IO String
	, fileRecWrite :: String -> IO ()
	}
socketFileRec socket = {
	  fileRecWrite = \ s -> send socket s 0
	, fileRecRead = \ i -> recv socket i 0
	}
pipeFileRec p0 p1 = {
	  fileRecWrite = writeFd p1
	, fileRecRead = readFd p0
	}
echoBlock file count = (fileRecRead file) count >>= fileRecWrite file

Maybe you could use that, maybe you couldn't.  That's why Martin suggested
that you reveal the actual problem.  Not the solution you had in mind,
but the thing you're trying to solve.

	Donn



More information about the Haskell-Cafe mailing list