From: charlie Date: Sun, 13 Dec 2015 12:44:56 +0000 (+0100) Subject: assignment 12 WIP X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=edd942d8e653b72b6c8107c47b2574bba4b63849;p=ap2015.git assignment 12 WIP --- diff --git a/a12/charlie/skeleton12.icl b/a12/charlie/skeleton12.icl new file mode 100644 index 0000000..6d300c3 --- /dev/null +++ b/a12/charlie/skeleton12.icl @@ -0,0 +1,105 @@ +module skeleton12 + +import Data.Maybe +import Control.Monad +import StdInt, StdString, StdBool + +class arith x where + lit :: a -> x a | toString a + (+.) infixl 6 :: (x a) (x a) -> x a | + a // integer addition, Boolean OR + (*.) infixl 7 :: (x a) (x a) -> x a | * a // integer multiplication, Boolean AND +class store x where + read :: (x Int) + write :: (x Int) -> x Int +class truth x where + (XOR) infixr 3 :: (x Bool) (x Bool) -> x Bool + -. :: (x Bool) -> x Bool +class (=.=) infix 4 x :: (x a) (x a) -> x Bool | == a +class except x where + throw :: (x a) + try :: (x a) (x a) -> x a + +class aexpr x | arith, store, except, =.= x +class bexpr x | arith, truth, except, =.= x +class expr x | aexpr, bexpr x + +:: Step a = Step (State -> (Maybe a, State)) +:: State :== Int + +instance Functor Step where + fmap f (Step g) = Step \st . h (g st) where + h (Just x, st) = (Just (f x), st) + h (Nothing, st) = (Nothing, st) + +instance Applicative Step where + pure x = Step \st . (Just x, st) + (<*>) (Step f) (Step g) = Step \st . h (f st) where + h (Just f, st) = q f (g st) + h (Nothing, st) = (Nothing, st) + q f (Just x, st) = (Just (f x), st) + q _ (Nothing, st) = (Nothing, st) + +instance Monad Step where + bind (Step f) g = Step \st . h (f st) where + h (Just x, st) = q (g x) st + h (Nothing, st) = (Nothing, st) + q (Step f) st = f st + +instance arith Step where + lit x = return x + (+.) x y = x >>= \x` . y >>= \y` . return (x`+y`) + (*.) x y = x >>= \x` . y >>= \y` . return (x`*y`) + +instance store Step where + read = Step \st . (Just st, st) + write x = x >>= \x` . Step \st . (Just x`, x`) + +instance truth Step where + (XOR) x y = x >>= \x` . y >>= \y` . return (x` bitxor y`) + -. x = x >>= \x` . return (not x`) + +seven :: e Int | aexpr e +seven = lit 3 +. lit 4 + +throw1 :: e Int | expr e +throw1 = lit 3 +. throw + +six :: e Int | expr e +six = write (lit 3) +. read + +try1 :: e Int | expr e +try1 = try throw1 (lit 42) + +/*loge :: e Bool | expr e +loge = lit True *. -. (lit True)*/ + +comp :: e Bool | expr e +comp = lit 1 =.= lit 2 XOR -. (-. (lit True)) + +:: Show a = Show ([String] -> [String]) + +instance arith Show where + lit x = Show \xs . [toString x:xs] + (+.) (Show f) (Show g) = Show \xs . f ["+":g xs] + (*.) (Show f) (Show g) = Show \xs . f ["*":g xs] + +instance store Show where + read = Show \xs . ["read":xs] + write (Show f) = Show \xs . ["write":f xs] + +instance truth Show where + (XOR) (Show f) (Show g) = Show \xs . f ["XOR":g xs] + -. (Show f) = Show \xs . ["!":f xs] + +instance =.= Show where + (=.=)(Show f) (Show g) = Show \xs . f ["==":g xs] + +instance except Show where + throw = Show \xs . ["throw":xs] + try (Show f) (Show g) = Show \xs . ["try":f ["catch":g xs]] + +show :: (Show a) -> [String] +show (Show f) = f [] + +Start :: Step Bool +Start = comp >>= return diff --git a/a12/charlie/skeleton12.prj b/a12/charlie/skeleton12.prj new file mode 100644 index 0000000..84f0abc --- /dev/null +++ b/a12/charlie/skeleton12.prj @@ -0,0 +1,490 @@ +Version: 1.4 +Global + ProjectRoot: . + Target: iTasks + Exec: {Project}\skeleton12.exe + CodeGen + CheckStacks: False + CheckIndexes: True + Application + HeapSize: 2097152 + StackSize: 512000 + ExtraMemory: 81920 + IntialHeapSize: 204800 + HeapSizeMultiplier: 4096 + ShowExecutionTime: False + ShowGC: False + ShowStackSize: False + MarkingCollector: False + StandardRuntimeEnv: True + Profile + Memory: False + MemoryMinimumHeapSize: 0 + Time: False + Stack: False + Output + Output: ShowConstructors + Font: Courier + FontSize: 9 + WriteStdErr: False + Link + LinkMethod: Static + GenerateRelocations: False + GenerateLinkMap: False + LinkResources: False + ResourceSource: + GenerateDLL: False + ExportedNames: + Paths + Path: {Project} + Precompile: + Postlink: +MainModule + Name: skeleton12 + Dir: {Project} + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False +OtherModules + Module + Name: StdArray + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdBool + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdChar + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdCharList + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdClass + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdEnum + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdEnv + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdFile + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdFunc + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdInt + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdList + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdMisc + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdOrdList + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdOverloaded + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdReal + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdString + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdTuple + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: _SystemArray + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: _SystemEnum + Dir: {Application}\Libraries\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: Control.Applicative + Dir: {Application}\iTasks-SDK\Dependencies\clean-platform\src\libraries\OS-Independent + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: Control.Monad + Dir: {Application}\iTasks-SDK\Dependencies\clean-platform\src\libraries\OS-Independent + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: Data.Func + Dir: {Application}\iTasks-SDK\Dependencies\clean-platform\src\libraries\OS-Independent + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: Data.Functor + Dir: {Application}\iTasks-SDK\Dependencies\clean-platform\src\libraries\OS-Independent + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: Data.List + Dir: {Application}\iTasks-SDK\Dependencies\clean-platform\src\libraries\OS-Independent + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: Data.Maybe + Dir: {Application}\iTasks-SDK\Dependencies\clean-platform\src\libraries\OS-Independent + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: Data.Monoid + Dir: {Application}\iTasks-SDK\Dependencies\clean-platform\src\libraries\OS-Independent + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: Data.Void + Dir: {Application}\iTasks-SDK\Dependencies\clean-platform\src\libraries\OS-Independent + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: System.IO + Dir: {Application}\iTasks-SDK\Dependencies\clean-platform\src\libraries\OS-Independent + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: _SystemDynamic + Dir: {Application}\iTasks-SDK\Patches\Dynamics + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: GenEq + Dir: {Application}\iTasks-SDK\Patches\Generics + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False + Module + Name: StdGeneric + Dir: {Application}\iTasks-SDK\Patches\StdEnv + Compiler + NeverMemoryProfile: False + NeverTimeProfile: False + StrictnessAnalysis: True + ListTypes: StrictExportTypes + ListAttributes: True + Warnings: True + Verbose: True + ReadableABC: False + ReuseUniqueNodes: True + Fusion: False