Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Simple Side Effect Control Suggestion

Name: Anonymous 2014-08-30 20:22

SSECS
BUTTSSECS

Anyway, here's a suggestion: how about we scrap the monads... okay-okay, monads are useful, but not for side effects control.

How about we take side effect control from the type system (which is poor at it) and move it to a separate layer of metadata? You've got several effectful language primitives and they're all "flagged", with the flags propagating to the caller and to the caller's caller and so on. E.g. mutation is done via the "set" primitive:

(set foo bar) ; gets flagged with {modifies FOO}

so when you've got a function that mutates something, that function gets the flag:

(def (mutator x) ; gets flagged with {mutates X}
(progn
(set x (+ x 1))
x))


and then

(def (iomutator x) ; gets flagged with {IO, mutates X}
(let ((y (mutator x)))
(print "Y is " y "X is " x)))


Then when you're defining a function, you can express constraints on the effect flags of its parameters:

(def (map f xs)
(:: (-> a b) (list a) (list b))
(:#: f {not IO, not mutates *})
;; definition of map)


But then - get this - you can compile in an effects-permissive mode. You can make the compiler allow calls of (map f xs) with effectful f (as long as it typechecks). Or you could make them compile-time errors. Because static reasoning about effects is immeasurably harder than reasoning about values, effect-checking should be optional while type-checking should be mandatory. So if you want effects to run galore, you flip the "effect-permissive" compiler option, and if you want to compile some untrusted code from some shithead, you flip the "effect-strict" option.

Name: Anonymous 2014-08-31 13:15

>>7
But returning a value is doing something.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List