module Example where

import POSIX

root w = class
	env = new posix w
	c = new mkC
	a = new mkA c env
	b = new mkB c env
	start = action
		env.stdin.installR a.input
		file <- env.openR "temp.txt"
		case file of
			Just f -> 
				f.installR b.text
			Nothing -> 
				env.stdout.write "File not found\n"
	result start

struct A where
	input :: String -> Action

mkA counter env = class
	input str = action
		count <- counter.m
		env.stdout.write (show count ++ "> Input: " ++ str ++ "\n")
	result {input = input}

struct B where
	text :: String -> Action
	print :: String -> Action

mkB counter env = class
	text str = action
		count <- counter.m
		after (sec 3) send print (show count ++ "> File: " ++ str ++ "\n")
	print str = action
		env.stdout.write str
	result {text = text; print = print}

struct C where
	m :: Request Int

mkC = class
	s := 0
	m = request
		s := s+1
		result s
	result {m = m}
		
