Extensible Effects An Alternative to Monad Transformers
|
|
|
- Victor Norton
- 9 years ago
- Views:
Transcription
1 Extensible Effects An Alternative to Monad Transformers Oleg Kiselyov Amr Sabry Cameron Swords Haskell Symposium 2013 Boston, MA Sep 23, 2013
2 We design and implement a library that solves the long-standing problem of combining effects without imposing restrictions on their interactions (such as static ordering). Effects arise from interactions between a client and an effect handler (interpreter); interactions may vary throughout the program and dynamically adapt to execution conditions. Existing code that relies on monad transformers may be used with our library with minor changes, gaining efficiency over long monad stacks. In addition, our library has greater expressiveness, allowing for practical idioms that are inefficient, cumbersome, or outright impossible with monad transformers. Our alternative to a monad transformer stack is a single monad, for the coroutine-like communication of a client with its handler. Its type reflects possible requests, i.e., possible effects of a computation. To support arbitrary effects and their combinations, requests are values of an extensible union type, which allows adding and, notably, subtracting summands. Extending and, upon handling, shrinking of the union of possible requests is reflected in its type, yielding a type-and-effect system for Haskell. The library is lightweight, generalizing the extensible exception handling to other effects and accurately tracking them in types.
3 2 Monad Transformers Monad Transformers and Modular Interpreters Sheng Liang and Paul Hudak and Mark Jones POPL Very recently, Cartwright and Felleisen [3] have independently proposed a modular semantics emphasizing a direct semantics approach, which seems somewhat more complex than ours; the precise relationship between the approaches is, however, not yet clear.
4 Effects in Haskell immediately evoke monad transformers, which were proposed, essentially in the same form we know now, in this classic, well-cited paper by Liang, Hudak and Jones from It is deservingly a classic paper. Here is the first page of the paper. If we scroll down to the bottom of it, we see a curious footnote, mentioning a paper that hardly anyone knows or remembers. There was an alternative to monad transformers! This whole talk at its heart is about this footnote. The relationship between the two approaches has become clear, and the alternative can be presented much simpler than it was originally.
5 EDLS I Extensible Denotational Language Specifications Robert Cartwright, Matthias Felleisen Theor. Aspects of Computer Software, The schema critically relies on the distinction between a complete program and a nested program phrase. A complete program is thought of as an agent that interacts with the outside world, e.g., a file system, and that affects global resources, e.g., the store. A central authority administers these resources. The meaning of a program phrase is a computation, which may be a value or an effect. If the meaning of a program phrase is an effect, it is propagated to the central authority. The propagation process adds a function to the effect package such that the central authority can resume the suspended calculation. We refer to this component of an effect package as the handle since it provides access to the place of origin for the package. 3
6 Here is this paper presenting the alternative approach. Curiously, it was published roughly at the same time as the Monad Transformers paper, just a couple of months earlier. Research in effects seems to be filled with amazing coincidences. The paper, especially the introduction, is very inspirational. I strongly recommend reading it. Let me show a few parts of the paper that directly inspired and are reflected in the work presented now. Cartwright and Felleisen were interested in extensible denotational specifications and hence building extensible interpreters. They really did it, starting from the language with only two constructs, for looping and failure. They add boolean algebra, arithmetic, call-by-name or by-value, state, etc. as extensions. You have probably read the highlighted paragraph. You see the word handle (and then handler ) that you ll hear again in this talk and in several ICFP talks. These term was coined in Our effect library pretty much reflects the quoted Cartwright and Felleisen s description.
7 4 Main ideas 1. An effect is most easily understood as an interaction between a sub-expression and a central authority that administers the global resources of a program. 2. an effect can be viewed as a message to the central authority plus enough information to resume the suspended calculation the program and its authority are like co-routines 3. the authority is part of the program, distributed throughout it: bureaucracy modularity and extensibility encapsulation of effects 4. types approximate possible effects, unordered collection: type-and-effect system
8 Let me summarize the main ideas. Cartwright and Felleisen propose to view effect as an interaction, communication with an authority in charge of resources. The interacting authority and the program may be viewed as coroutines. The last two points are our departure from Cartwright and Felleisen. When the authority is part of user program and distributed throughout it, it is easier to add new effects (compared to the extension of the monolithic central authority) and it becomes possible to encapsulate effects, limiting them to parts of the program. Also unlike EDLS, we use types as a conservative approximation of effects an expression may perform. We thus get a type and effect system. If you understand these ideas, you can write your own library of extensible effects. Let me briefly describe how we did it.
9 5 Outline Limits of monad transformers Extensible effects, the library Extensible effects: beyond the limits of MTL Frequently Expressed Confusions Isn t this just Data types à la carte? Isn t this just a Free Monad? Typeable is ugly! OverlappingInstances are ugly! Extensible effects vs Algebraic effects? OCaml polymorphic variants vs OpenUnion? Concluding remarks
10 Looking at alternatives is worthwhile in and of itself. Yet some may say, if Monad Transformers work so well, what s the problem then? We show a simple example, implemented with the monad transformer library (MTL): to remind of monad transformers and to demonstrate they do have a problem. We then demonstrate one implementation of the main ideas of the alternative approach, which we just saw. The alternative looks and feels very much like MTL, but goes beyond its limits.
11 6 Running example Given comp :: Monad m m Int Tasks 1. if the result is too big, throw TooBig exception 2. recover from that exception
12 Here is the specification of our running example, to illustrate monad transformers and their limitations, and extensible effects overcoming them. Suppose we have a computation in some monad m producing an Int. First, we check the result against a threshold. If it s bigger, throw the exception TooBig. In the second part of the example, we should recover from the exception.
13 7 Running example in MTL 1 newtype TooBig = TooBig Int deriving Show ex2 :: MonadError TooBig m m Int m Int ex2 m = do v m if v > 5 then throwerror (TooBig v) else return v
14 Here is the most elegant implementation with the Monad Transformer Library (MTL). We define the data type to use as an exception. We throw the TooBig value if the result of the argument computation m is bigger than our threshold, 5. The use of throwerror induces the constraint MonadError: the monad m must be an error monad. The code is intuitive, elegant and clearly express our intention. Let s see how it works.
15 8 Running example in MTL 2 ex2 :: MonadError TooBig m m Int m Int ex2 m = do v m if v > 5 then throwerror (TooBig v) else return v choose :: MonadPlus m [a] m a runlistt :: ListT m a m [a] runerrort :: ErrorT e m a m (Either e a) Fixing the order runidentity runlistt runerrort $ ex2 (choose [5,7,1])
16 Our guard ex2 should work with any computation. As a computation to guard, we take non-deterministic choice of an integer out of three: 5, 7 or 1. We need a MonadPlus monad to program such choice. We can now try running the example. But we need to choose a monad that has the properties of being an error monad and a non-determinism monad. In MTL, monads with desired properties are composed by layering of monad transformers responsible for a single property. For example, ListT applied to some m makes the monad that supports non-determinism (a member of the type class MonadPlus). The function runlistt peels off the layer, returning all choices in a list. ErrorT e adds supports for throwing exceptions of type e. We must fix the order of layers though. It is fixed by choosing the order of the run functions. Here, the order is: Identity transformed by ListT transformed by ErrorT. The order remain fixed throughout the computation.
17 8 Running example in MTL 2 ex2 :: MonadError TooBig m m Int m Int ex2 m = do v m if v > 5 then throwerror (TooBig v) else return v choose :: MonadPlus m [a] m a runlistt :: ListT m a m [a] runerrort :: ErrorT e m a m (Either e a) Fixing the order runidentity runlistt runerrort $ ex2 (choose [5,7,1]) [Right 5]
18 The result is quite surprising. We see no shred of the TooBig exception, which was supposed to be thrown. Also, the choice 1 is gone. It is a puzzle indeed. It is an exercise to the audience to determine what is going on.
19 8 Running example in MTL 2 ex2 :: MonadError TooBig m m Int m Int ex2 m = do v m if v > 5 then throwerror (TooBig v) else return v choose :: MonadPlus m [a] m a runlistt :: ListT m a m [a] runerrort :: ErrorT e m a m (Either e a) Fixing the order runidentity runlistt runerrort $ ex2 (choose [5,7,1]) [Right 5] runidentity runerrort runlistt $ ex2 (choose [5,7,1]) Left (TooBig 7)
20 What if we choose the different order of layers? This time, we see the exception thrown, as expected. So, the order of layers matters a great deal. Well, at least one order of layers has worked for us. But we are not done yet. There is the second part of the example: error recovery.
21 9 Running example in MTL 3 ex2 :: MonadError TooBig m m Int m Int ex2 m = do v m if v > 5 then throwerror (TooBig v) else return v exrec :: MonadError TooBig m m Int m Int exrec m = catcherror m handler where handler (TooBig n) n 7 = return n handler e = throwerror e
22 The MonadError type class offers not only throwerror to throw errors but also catcherror to handle them. We can catch the TooBig exception and examine it. If the result is really not that big, not exceeding 7, we then continue the execution, recovering from the error. Otherwise, we re-throw the error. Let us see how it works, using the winning order of the layers.
23 9 Running example in MTL 3 ex2 :: MonadError TooBig m m Int m Int ex2 m = do v m if v > 5 then throwerror (TooBig v) else return v exrec :: MonadError TooBig m m Int m Int exrec m = catcherror m handler where handler (TooBig n) n 7 = return n handler e = throwerror e runidentity runerrort runlistt $ exrec (ex2 (choose [5,7,1])) Right [7] Wanted: per world exception and recovery
24 Well, it doesn t work too well. The original computation had three non-deterministic choices. Two of them should not trigger any error, and one triggers the TooBig exception, which is supposed to be recovered from. So, the result should have three choices, but we got only one. The other two got lost. We would really wanted that exception did not interfere with choices, was limited to its possible world. We tried the two possible ordering of the monad transformer layers and could not get what we wanted, per-world exception and recovery. Simple variations lead to the similar disappointment. Actually we are lucky: it is possible to implement our example, with per world exception and recovery, using MTL. But we need two error layers. To see how easy or intuitive it is, I encourage the audience to write that code.
25 10 MTL Problems Fixed order of layers throughout the computation: limited expressivity Complexity (quadratic) of lifting Performance degradation on large transformer stacks
26 So, monad transformers do have problems. The principal problem is the fixed order of monad transformer layers. The order matters, since it defines how effects, exceptions and non-determinism, interact. If the order is fixed throughout the whole computation, we cannot express computations that require more flexible interaction. We were lucky that we could after all implement our running example as intended, albeit unintuitively and with performance degradation. The paper outlines a different example, with coroutines and dynamic binding, the Reader monad. There does not seem to be any way to implement that example in its full form with MTL, by composing independent layers of effects. There are other problems of MTL, please see the paper for their discussion.
27 11 Alternative: Extensible Effects effect as a communication with an authority the program and its authority are like coroutines the authority is part of the program: bureaucracy types approximate possible effects
28 Let s recall what ve learned from the Cartwright and Felleisen s paper, and from contemplating extensions to it. Let us see how we can implement them in Haskell.
29 11 Alternative: Extensible Effects effect as a communication with an authority the program and its authority are like coroutines type Eff r a instance Monad (Eff r) run :: Eff Void w w send req :: (Suspension a Request) Eff r a the authority is part of the program: bureaucracy types approximate possible effects
30 First, we need coroutines. Let s pick a monadic implementation of coroutines out of several available, and call it monad Eff r. We will come to this r parameter of the monad in a moment. A coroutine monad will have an operation to run it; let s call it run. Again, please disregard the void for a moment. A coroutine monad obviously has an operation for a coroutine to resume its caller, and suspend. Let s call this operation send req. Its argument is a function that takes a suspension, the return address, and incorporates it into the request; send req will then send the request and suspend. When the coroutine resumes, it receives the value of the type a and continues.
31 11 Alternative: Extensible Effects effect as a communication with an authority the program and its authority are like coroutines type Eff r a instance Monad (Eff r) run :: Eff Void w w send req :: (Suspension a Request) Eff r a the authority is part of the program: bureaucracy data VE w r = Val w E (Union r (VE w r)) cf. free monad admin :: Eff r w VE w r cf. try handle relay :: Union (req r) v (v Eff r a) (req v Eff r a) Eff r a types approximate possible effects
32 The authority, bureaucracy, is part of the program. So, we should be able to program it as well. First, the bureaucrat needs to know if the supervised program fragment has finished, with the value w, or has sent a request. Recall, Cartwright and Felleisen wrote: The meaning of a program phrase is a computation, which may be a value or an effect. The function admin, which should be provided by the coroutine library, does this. Recall that bureaucracy is distributed: each particular bureaucrat, or handler, is responsible only for one or a couple of specific requests. A program may perform several effects, that is, send several requests. Thus a bureaucrat has do determine if the request of the type it can handle. If not, the request should be relayed upstairs. The function handle relay does the case analysis. It checks if the current request, contained in the union of possible request, is of the desired type req. If so, it calls the supplied handler (the last argument of the function). The function handle relay is provided by the library of open unions.
33 Alternative: Extensible Effects effect as a communication with an authority the program and its authority are like coroutines type Eff r a instance Monad (Eff r) run :: Eff Void w w send req :: (Functor req, Member req r) ( w. (a VE w r) req (VE w r)) Eff r a the authority is part of the program: bureaucracy data VE w r = Val w E (Union r (VE w r)) cf. free monad admin :: Eff r w VE w r cf. try handle relay :: Union ( req r) v (v Eff r a) (req v Eff r a) Eff r a types approximate possible effects handled effects are subtracted from the type assure: there is a handler for each request 11
34 Finally, we need types that tell which effects a program fragment may possibly do. Here is where that r parameter comes in. The coroutine monad is indexed by r, the type of possible requests. One may think of this type as a set of possible requests. Void denotes the empty set. Therefore, we can run only uneffectful computations, whose effects are all handled. The notation req r denotes a set with the element req added to r. Therefore, when the bureaucrat handles req, the computation no longer has that req (see the handle relay.) In other words, handled effects are subtracted from the effect type. Here is the full type of send req: it shows that the request req we are sending has to be a member of the set r. That is, the whole program must have a bureaucrat that can handle the request. That is all there is to it. We can re-implement the whole MTL, and we can do more.
35 12 Extensible Effects: Error effect newtype Exc e v = Exc e throwerror :: (Member (Exc e) r) e Eff r a throwerror e = send req (const $ Exc e) runerror :: Eff (Exc e r) a Eff r (Either e a) runerror m = loop (admin m) where loop (Val x) = return (Right x) loop (E u) = handle relay u loop (\(Exc e) return (Left e)) catcherror :: (Member (Exc e) r) Eff r a (e Eff r a) Eff r a No need for MonadError
36 Let s implement the effect of throwing an exception (of type e) in our framework. Exc e v is the type of the request, with v being the result to be produced by a suspension. Since the program, after requesting an exception, is not resumed, we ignore v. Throwing an exception makes the request. The interpreter, the bureaucrat, runerror returns the result of the supervised computation tagged with Right. If the computation requested an exception, the exception value e is returned, without resuming the computation. If the computation made some other request, it is relayed upstairs. After the higher bureaucrat replied, we continue the supervision. Our library implements this Error effect and other MTL effects. We no longer need to define a type class per effect. In MTL, it hid the ordering of the layers. Now, the ordering is hidden anyway, by the constraint Member.
37 13 Back to the running example 1 newtype TooBig = TooBig Int deriving (Show, Typeable) ex2 :: Member (Exc TooBig) r Eff r Int Eff r Int ex2 m = do v m if v > 5 then throwerror (TooBig v) else return v exrec :: Member (Exc TooBig) r Eff r Int Eff r Int exrec m = catcherror m handler where handler (TooBig n) n 7 = return n handler e = throwerror e
38 Let s come back to our running example and re-implement it with extensible effects. The code looks exactly the same as it was with MTL. Only type signatures differ. The type signatures are all inferred.
39 14 Back to the running example 2 ex2 :: Member (Exc TooBig) r Eff r Int Eff r Int ex2 (choose [5,7,1]) :: (Member Choose r, Member (Exc TooBig) r) Eff r Int
40 We see the encapsulation of effects. As we add handlers, the type becomes smaller as effects are handled.
41 14 Back to the running example 2 ex2 :: Member (Exc TooBig) r Eff r Int Eff r Int runerrbig :: Eff (Exc TooBig r) a Eff r (Either TooBig a) runerrbig m = runerror m ex2 (choose [5,7,1]) :: ( Member Choose r, Member (Exc TooBig) r) Eff r Int runerrbig $ ex2 (choose [5,7,1]) :: Member Choose r Eff r (Either TooBig Int)
42 14 Back to the running example 2 ex2 :: Member (Exc TooBig) r Eff r Int Eff r Int runerrbig :: Eff (Exc TooBig r) a Eff r (Either TooBig a) makechoice :: Eff (Choose r) a Eff r [ a] ex2 (choose [5,7,1]) :: (Member Choose r, Member (Exc TooBig) r) Eff r Int runerrbig $ ex2 (choose [5,7,1]) :: Member Choose r Eff r (Either TooBig Int) makechoice runerrbig $ ex2 (choose [5,7,1]) :: Eff r [ Either TooBig Int] run makechoice runerrbig $ ex2 (choose [5,7,1]) [ Right 5, Left (TooBig 7),Right 1]
43 When all effects are handled, we can finally run the computation. Of three choices, one ended in error, the others normally. There are no surprises.
44 15 Back to the running example 3 exrec :: Member (Exc TooBig) r Eff r Int Eff r Int run runerrbig makechoice $ exrec (ex2 (choose [5,7,1])) Right [5,7,1] run makechoice runerrbig $ exrec (ex2 (choose [5,7,1])) [Right 5,Right 7,Right 1]
45 Quickly, error recovery. According to our thresholds, 7 is too big but not too big. So, when it comes to 7, an exception should be raised, and should be recovered from. That s exactly the result we get. There are no lost choices any more. If we switch the order of the handlers, the return type obviously changes, but the overall result stays the same. The exception is handled, no choices gone missing. There are no surprises.
46 16 Choice effect data Choose v = a. Choose [a] (a v) deriving (Typeable) choose :: Member Choose r [a] Eff r a choose lst = send (\k inj $ Choose lst k) mzero :: Member Choose r Eff r a mzero = choose [] mplus m1 m2 = choose [m1,m2] = id
47 We have time to see the implementation of the Choice effect, with the choose request, which expresses the familiar MonadPlus operators mzero and mplus.
48 17 Choice effect: handler makechoice :: a r. Eff (Choose r) a Eff r [ a] makechoice m = loop (admin m) where loop (Val x) = return [ x] loop (E u) = handle relay u loop (\(Choose lst k) handle lst k handle :: [ t] (t VE a (Choose r)) Eff r [ a] handle [] = return [] handle [ x] k = loop (k x) handle lst k = fmap concat $ mapm (loop k) lst
49 The handler of choose requests implements DFS. One can see the similarity with the list monad: cf. concatmap
50 18 Choice effect: Soft cut (LogicT) Non-deterministic if-then-else, aka Prolog s *-> ifte t th el (t = th) mplus ((not t) el ) but t is evaluated only once
51 The choice effect implements not just the MonadPlus interface but also LogicT, in particular, soft cut. That is, ifte t th el is equivalent to t >>= th if t has at least one solution. If t fails, ifte t th el is the same as el. To implement soft cut, we should sort of look-ahead into the test t to see it succeeds at least once. Hence we need to convert a computation to its representation, so we can look into it.
52 18 Choice effect: Soft cut (LogicT) Non-deterministic if-then-else, aka Prolog s *-> ifte t th el (t = th) mplus ((not t) el ) but t is evaluated only once Monadic reification admin :: Eff r w VE w r admin (Eff m) = m Val
53 But we had been doing it all along: admin. More technically, it is called reification.
54 Choice effect: Soft cut (LogicT) Non-deterministic if-then-else, aka Prolog s *-> ifte t th el (t = th) mplus ((not t) el ) but t is evaluated only once Monadic reification admin :: Eff r w VE w r admin (Eff m) = m Val Monadic reflection reflect :: VE a r Eff r a reflect (Val x) = return x reflect (E u) = Eff (\k E $ fmap (loop k) u) where loop :: (a VE w r) VE a r VE w r loop k (Val x) = k x loop k (E u) = E $ fmap (loop k) u Monadic reification and reflection are generic 18
55 For soft-cut, we also need the inverse operation: We have disassembled t and looked inside and saw if it fails or not. If we found it does not fail, we have to put it back together, to implement t >>= th. We need so-called reflection. It is also implementable. The shown implementation is not efficient; that can be fixed. What interesting is that normally reification and reflection require separate implementation per each effect. With extensible effects, they are written generically.
56 19 Choices how to implement coroutines use OverlappingInstances and Typeable use closed type families instead of OverlappingInstances use neither OverlappingInstances nor Typeable allow or prohibit the duplication of effect descriptors in types allow or prohibit different types of monad readers...
57 The design space is quite large. For example, there are several ways to implement coroutines and sending of messages; there are several ways to implement open unions. We explored a few options, shown on the slide; more remain. In our implementation, Open unions it is a true union: union of a and a is a.
58 20 Frequently Expressed Confusions Isn t this just Data types à la carte? Isn t this just a Free Monad? Typeable is ugly! OverlappingInstances are ugly! Extensible effects vs Algebraic effects? OCaml polymorphic variants vs OpenUnion?
59 There has been a fair amount of discussion of extensible effects on various forums like reddit. Alas, not all of it has been well-informed. Quite a bit of misunderstanding was expressed. Let me try to clear it.
60 21 Isn t this just Data types à la carte? Similarities Requests and their interpreters Extensibility: more requests Open Unions Differences lack the encapsulation of effects lack effect inference
61 The biggest confusion is about extensible effects and Swierstra s data types à la carte. There are many similarities, to be sure. One of them is open unions which have been implemented already in Liang et al. MTL paper. This is not surprising: any extensible interpreter has to have open unions for terms it interprets. The EDSL paper has open unions too.
62 22 Isn t this just Data types à la carte? data Incr t = Incr Int t data Recall t = Recall (Int t) incr :: (Incr : <: f ) Int Term f () incr i = inject (Incr i (Pure ())) recall :: (Recall : <: f ) Term f Int recall = inject (Recall Pure)
63 This is an example from the Data types à la carte paper, the implementation of a State effect with two operations: to increment the integer state and to get it. Defining and sending of the requests is essentially the same as with extensible effects.
64 23 Isn t this just Data types à la carte? newtype Mem = Mem Int class Functor f Run f where runalgebra :: f (Mem (a, Mem)) (Mem (a, Mem)) instance Run Incr where runalgebra (Incr k r) (Mem i ) = r (Mem (i + k )) instance Run Recall where runalgebra (Recall r) (Mem i ) = r i (Mem i ) instance (Run f, Run g) Run (f : + : g) where runalgebra (Inl r) = runalgebra r runalgebra (Inr r) = runalgebra r Lack of encapsulation Type class Run is global (and unnecessary)
65 This is the handler part: and it is very different. With extensible effects, we never had to define a type class for a handler, had we?
66 23 Isn t this just Data types à la carte? newtype Mem = Mem Int class Functor f Run f where runalgebra :: f (Mem (a, Mem)) (Mem (a, Mem)) run :: Run f Term f a Mem (a, Mem) run = foldterm (,) runalgebra Lack of encapsulation Type class Run is global (and unnecessary) run handles all effects rather than some of them Term f is extensible but not shrinkable
67 The main difference from extensible effects is in the signature of run: its return type is not a Term f a. That is, run is a complete interpreter, rather than a handler of some requests, letting other handlers do their part. There is no effect encapsulation. Correspondingly, open unions in the Data types à la carte paper do not support the decomposition operation.
68 24 Isn t this just a Free Monad? data VE w r = Val w E (Union r (VE w r)) instance Functor (Union r) where Free Monad is an accident The bind on VE w r is never used There are other implementations, without Functor
69 If we look carefully at the type VE, we see that VE w r with the flipped arguments is a free monad, over a functor Union r. This is somewhat of an accident. A handler needs to rethrow any request it does not understand. One way of implementing it is for the handler to forward the request to a handler upstairs, and then relay its reply. For the latter, the handler needs to send a reply to a request of an unknown form. The Functor constraint is enough to ensure that. In this design, the handler is able to do finalization for any request, even the ones it does not understand. However, the request relay may be implemented differently, without the functor constraint. In that case, the handler can do finalization only for known requests.
70 25 Typeable is ugly! OverlappingInstances are ugly! module OpenUnion1... where data Union r v where Union :: (Functor t, Typeable1 t) Id (t v) Union r v class Member (t :: ) r instance Member t (t r) instance Member t r Member t (t r) However, other implementations of open unions use neither Typeable nor OverlappingInstances OverlappingInstances in Member: no closed type families until GHC 7.8 These are all implementation details
71 You may be wondering what Typeable and OverlappingInstances I am talking about. They appear in one implementation of open unions, OpenUnion1, which I have not shown you. Here I have to reveal the details. I did not show you the implementation deliberately: there are other implementations of open unions, which use neither feature. Also, OverlappingInstances were the artifact: GHC 7.8 released the other day supports closed type families, and the overlapping instances are no longer needed. So the main message: there is nothing in extensible effects that needs these features. Let s not focus on implementation details.
72 26 Extensible effects vs Algebraic effects? The general coroutine effect data Yield a b v = Yield a (b v) deriving (Typeable, Functor) yield :: (Typeable a, Member (Yield a b) r) a Eff r b yield x = send (inj Yield x) data Y r a b = Done Y a (b Eff r (Y r a b)) runc :: Typeable a Eff (Yield a b r) w Eff r (Y r a b) runc m = loop (admin m) where loop (Val x) = return Done loop (E u) = handle relay u loop $ \(Yield x k) return (Y x (loop k)) General delimited continuation effects are not algebraic
73 Here is a simple implementations of generalized coroutines, which can be resumed more than once. Such coroutines are equivalent in expressive power to delimited control. Delimited control effects are not algebraic. So, extensible effects easily deals with non-algebraic effects.
74 27 OCaml polymorphic variants vs OpenUnion? Tags do not have to be declared, extensible type # ta 1 : [ > ta of int ] = ta 1
75 27 OCaml polymorphic variants vs OpenUnion? Tags do not have to be declared, extensible type Order does not matter # fun x if x then ta 1 else tb 2.0 : bool [ > ta of int tb of float ] = <fun> # let f = fun x if x then tb 2.0 else ta 1 val f : bool [ > ta of int tb of float ] = <fun>
76 27 OCaml polymorphic variants vs OpenUnion? Tags do not have to be declared, extensible type Order does not matter Static check: all possibilities are handled # let f = fun x if x then tb 2.0 else ta 1 val f : bool [ > ta of int tb of float ] = <fun> # fun x match f x with ta x x;; Error : This pattern matches values of type [< ta of a ] but a pattern was expected which matches values of type [ > ta of int tb of float ] The first variant type does not allow tag(s) tb
77 27 OCaml polymorphic variants vs OpenUnion? Tags do not have to be declared, extensible type Order does not matter Static check: all possibilities are handled Alas: pattern-match doesn t remove variants No encapsulation # let f = fun x if x then tb 2.0 else ta 1 val f : bool [ > ta of int tb of float ] = <fun> # fun x match f x with ta (y: int ) None y Some y;; : bool [ > ta of int tb of float ] option = <fun>
78 28 Conclusions A framework for extensible effects modularity, extensibility, encapsulation of effects type-and-effect system handling effects individually or in groups, interleaving subsumes MTL Effect is an interaction Think in terms of desired effects rather than MTL layers what effect we want to achieve rather than which monad transformer to use
79 We have presented an extension of Cartwright and Felleisen approach to modular effect handling, and described one of its implementation in Haskell. Our framework induces a type and effect system for Haskell. It subsumes MTL: it can be used quite like MTL but offers flexibility of effect handling and interaction, without fixed lifting. The take-away is the view of effects as interaction, between an expression and the interpreter. And the other thought: when designing a program we should start thinking what effect we want to achieve rather than which monad transformer to use. Using ReaderT or StateT or something else is an implementation detail. Once we know what effect to achieve we can write a handler, or interpreter, to implement the desired operation on the World, obeying the desired equations. And we are done. Defining a new class for each effect is possible but not needed at all. With monad transformers, a class per effect is meant to hide the ordering of transformer layers in a monad transformer stack. Effect libraries abstract over the implementation details out of the box. Crutches extra classes are unnecessary. Some papers become popular, some other, just as inspirational, sink to obscurity. I m happy have a chance to bring attention to Cartwright and Felleisen s paper, which should be read and remembered.
[Refer Slide Time: 05:10]
Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture
Chapter 7: Functional Programming Languages
Chapter 7: Functional Programming Languages Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Fun: a language
COLLEGE ALGEBRA. Paul Dawkins
COLLEGE ALGEBRA Paul Dawkins Table of Contents Preface... iii Outline... iv Preliminaries... Introduction... Integer Exponents... Rational Exponents... 9 Real Exponents...5 Radicals...6 Polynomials...5
A CONSTRUCTION OF THE UNIVERSAL COVER AS A FIBER BUNDLE
A CONSTRUCTION OF THE UNIVERSAL COVER AS A FIBER BUNDLE DANIEL A. RAMRAS In these notes we present a construction of the universal cover of a path connected, locally path connected, and semi-locally simply
Regular Expressions and Automata using Haskell
Regular Expressions and Automata using Haskell Simon Thompson Computing Laboratory University of Kent at Canterbury January 2000 Contents 1 Introduction 2 2 Regular Expressions 2 3 Matching regular expressions
Notes on Factoring. MA 206 Kurt Bryan
The General Approach Notes on Factoring MA 26 Kurt Bryan Suppose I hand you n, a 2 digit integer and tell you that n is composite, with smallest prime factor around 5 digits. Finding a nontrivial factor
Adding GADTs to OCaml the direct approach
Adding GADTs to OCaml the direct approach Jacques Garrigue & Jacques Le Normand Nagoya University / LexiFi (Paris) https://sites.google.com/site/ocamlgadt/ Garrigue & Le Normand Adding GADTs to OCaml 1
Revised Version of Chapter 23. We learned long ago how to solve linear congruences. ax c (mod m)
Chapter 23 Squares Modulo p Revised Version of Chapter 23 We learned long ago how to solve linear congruences ax c (mod m) (see Chapter 8). It s now time to take the plunge and move on to quadratic equations.
How to Study Mathematics Written by Paul Dawkins
How to Study Mathematics Written by Paul Dawkins Before I get into the tips for how to study math let me first say that everyone studies differently and there is no one right way to study for a math class.
The Clean programming language. Group 25, Jingui Li, Daren Tuzi
The Clean programming language Group 25, Jingui Li, Daren Tuzi The Clean programming language Overview The Clean programming language first appeared in 1987 and is still being further developed. It was
MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.
MATH10212 Linear Algebra Textbook: D. Poole, Linear Algebra: A Modern Introduction. Thompson, 2006. ISBN 0-534-40596-7. Systems of Linear Equations Definition. An n-dimensional vector is a row or a column
The Basics of Graphical Models
The Basics of Graphical Models David M. Blei Columbia University October 3, 2015 Introduction These notes follow Chapter 2 of An Introduction to Probabilistic Graphical Models by Michael Jordan. Many figures
Writing Thesis Defense Papers
Writing Thesis Defense Papers The point of these papers is for you to explain and defend a thesis of your own critically analyzing the reasoning offered in support of a claim made by one of the philosophers
Club Accounts. 2011 Question 6.
Club Accounts. 2011 Question 6. Anyone familiar with Farm Accounts or Service Firms (notes for both topics are back on the webpage you found this on), will have no trouble with Club Accounts. Essentially
Cobol. By: Steven Conner. COBOL, COmmon Business Oriented Language, one of the. oldest programming languages, was designed in the last six
Cobol By: Steven Conner History: COBOL, COmmon Business Oriented Language, one of the oldest programming languages, was designed in the last six months of 1959 by the CODASYL Committee, COnference on DAta
Practical Generic Programming with OCaml
Practical Generic Programming with OCaml Jeremy Yallop LFCS, University of Edinburgh ML Workshop 2007 Instead of this... type α tree = Node of α Branch of (α tree) (α tree) val show_tree : (α string) (α
Chapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named
How to Overcome the Top Ten Objections in Credit Card Processing
How to Overcome the Top Ten Objections in Credit Card Processing Section #1: Handling the Red Flags Just Fax Your Rates Response: I ll be happy to do that, but until we know if this is truly a fit for
Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions
COMP209 Object Oriented Programming Designing Classes 2 Mark Hall Programming by Contract (adapted from slides by Mark Utting) Preconditions Postconditions Class invariants Programming by Contract An agreement
1 Uncertainty and Preferences
In this chapter, we present the theory of consumer preferences on risky outcomes. The theory is then applied to study the demand for insurance. Consider the following story. John wants to mail a package
The Rules 1. One level of indentation per method 2. Don t use the ELSE keyword 3. Wrap all primitives and Strings
Object Calisthenics 9 steps to better software design today, by Jeff Bay http://www.xpteam.com/jeff/writings/objectcalisthenics.rtf http://www.pragprog.com/titles/twa/thoughtworks-anthology We ve all seen
PostgreSQL Concurrency Issues
PostgreSQL Concurrency Issues 1 PostgreSQL Concurrency Issues Tom Lane Red Hat Database Group Red Hat, Inc. PostgreSQL Concurrency Issues 2 Introduction What I want to tell you about today: How PostgreSQL
Programming and Reasoning with Algebraic Effects and Dependent Types
Programming and Reasoning with Algebraic Effects and Dependent Types Edwin C. Brady School of Computer Science, University of St Andrews, St Andrews, Scotland. Email: [email protected] Abstract One
Hypercosm. Studio. www.hypercosm.com
Hypercosm Studio www.hypercosm.com Hypercosm Studio Guide 3 Revision: November 2005 Copyright 2005 Hypercosm LLC All rights reserved. Hypercosm, OMAR, Hypercosm 3D Player, and Hypercosm Studio are trademarks
Probability and Expected Value
Probability and Expected Value This handout provides an introduction to probability and expected value. Some of you may already be familiar with some of these topics. Probability and expected value are
>> My name is Danielle Anguiano and I am a tutor of the Writing Center which is just outside these doors within the Student Learning Center.
>> My name is Danielle Anguiano and I am a tutor of the Writing Center which is just outside these doors within the Student Learning Center. Have any of you been to the Writing Center before? A couple
Concepts and terminology in the Simula Programming Language
Concepts and terminology in the Simula Programming Language An introduction for new readers of Simula literature Stein Krogdahl Department of Informatics University of Oslo, Norway April 2010 Introduction
Chapter 7. Functions and onto. 7.1 Functions
Chapter 7 Functions and onto This chapter covers functions, including function composition and what it means for a function to be onto. In the process, we ll see what happens when two dissimilar quantifiers
How to Name Your Tours & Activities: A Data Driven Guide
How to Name Your Tours & Activities: A Data Driven Guide How much thought do you put into naming your tours and activities? If you have your hands full running your business I m guessing it s not high
Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6
Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6 Number Systems No course on programming would be complete without a discussion of the Hexadecimal (Hex) number
Chapter Four: How to Collaborate and Write With Others
Chapter Four: How to Collaborate and Write With Others Why Collaborate on Writing? Considering (and Balancing) the Two Extremes of Collaboration Peer Review as Collaboration * A sample recipe for how peer
Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example
Overview Elements of Programming Languages Lecture 12: Object-oriented functional programming James Cheney University of Edinburgh November 6, 2015 We ve now covered: basics of functional and imperative
Chapter 15 Functional Programming Languages
Chapter 15 Functional Programming Languages Introduction - The design of the imperative languages is based directly on the von Neumann architecture Efficiency (at least at first) is the primary concern,
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful
POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful RALF HINZE Institute of Information and Computing Sciences Utrecht University Email: [email protected] Homepage: http://www.cs.uu.nl/~ralf/
CS355 Hw 3. Extended Shell with Job Control
CS355 Hw 3 Due by the end of day Tuesday, Mar 18. Design document due on Thursday, Feb 27 in class. Written supplementary problems due on Thursday, March 6. Programming Assignment: You should team up with
Fun with Phantom Types
1 Fun with Phantom Types RALF HINZE Institut für Informatik III, Universität Bonn Römerstraße 164, 53117 Bonn, Germany Email: [email protected] Homepage: http://www.informatik.uni-bonn.de/~ralf
5544 = 2 2772 = 2 2 1386 = 2 2 2 693. Now we have to find a divisor of 693. We can try 3, and 693 = 3 231,and we keep dividing by 3 to get: 1
MATH 13150: Freshman Seminar Unit 8 1. Prime numbers 1.1. Primes. A number bigger than 1 is called prime if its only divisors are 1 and itself. For example, 3 is prime because the only numbers dividing
An Innocent Investigation
An Innocent Investigation D. Joyce, Clark University January 2006 The beginning. Have you ever wondered why every number is either even or odd? I don t mean to ask if you ever wondered whether every number
1.1 WHAT IS A PROGRAMMING LANGUAGE?
1 INTRODUCTION 1.1 What is a Programming Language? 1.2 Abstractions in Programming Languages 1.3 Computational Paradigms 1.4 Language Definition 1.5 Language Translation 1.6 Language Design How we communicate
(Common) Shock models in Exam MLC
Making sense of... (Common) Shock models in Exam MLC James W. Daniel Austin Actuarial Seminars www.actuarialseminars.com June 26, 2008 c Copyright 2007 by James W. Daniel; reproduction in whole or in part
3.2 The Factor Theorem and The Remainder Theorem
3. The Factor Theorem and The Remainder Theorem 57 3. The Factor Theorem and The Remainder Theorem Suppose we wish to find the zeros of f(x) = x 3 + 4x 5x 4. Setting f(x) = 0 results in the polynomial
Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration
Lab 4.4 Secret Messages: Indexing, Arrays, and Iteration This JavaScript lab (the last of the series) focuses on indexing, arrays, and iteration, but it also provides another context for practicing with
Describing, manipulating and pricing financial contracts: The MLFi language
Describing, manipulating and pricing financial contracts: The MLFi language Centre for Financial Research, Judge Institute of Management Cambridge, 14 March 2003 (revised January 2005) Jean-Marc Eber LexiFi,
LESSON 1. Opening Leads Against Notrump Contracts. General Concepts. General Introduction. Group Activities. Sample Deals
LESSON 1 Opening Leads Against Notrump Contracts General Concepts General Introduction Group Activities Sample Deals 8 Defense in the 21st Century GENERAL CONCEPTS Defense The opening lead against notrump
Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.
Coding Rules Section A: Linux kernel style based coding for C programs Coding style for C is based on Linux Kernel coding style. The following excerpts in this section are mostly taken as is from articles
A free guide for readers of Double Your Business. By Lee Duncan www.double Your Business.com
7 Factors to increase the leads you generate from Pay Per Click advertising with Google Adwords. Exclusively for readers of Double Your Business. A free guide for readers of Double Your Business By Lee
1.7 Graphs of Functions
64 Relations and Functions 1.7 Graphs of Functions In Section 1.4 we defined a function as a special type of relation; one in which each x-coordinate was matched with only one y-coordinate. We spent most
Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.
Unit 1 Number Sense In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions. BLM Three Types of Percent Problems (p L-34) is a summary BLM for the material
Why is Insurance Good? An Example Jon Bakija, Williams College (Revised October 2013)
Why is Insurance Good? An Example Jon Bakija, Williams College (Revised October 2013) Introduction The United States government is, to a rough approximation, an insurance company with an army. 1 That is
Introduction to Hypothesis Testing
I. Terms, Concepts. Introduction to Hypothesis Testing A. In general, we do not know the true value of population parameters - they must be estimated. However, we do have hypotheses about what the true
NUMBER SYSTEMS APPENDIX D. You will learn about the following in this appendix:
APPENDIX D NUMBER SYSTEMS You will learn about the following in this appendix: The four important number systems in computing binary, octal, decimal, and hexadecimal. A number system converter program
Object-Oriented Software Specification in Programming Language Design and Implementation
Object-Oriented Software Specification in Programming Language Design and Implementation Barrett R. Bryant and Viswanathan Vaidyanathan Department of Computer and Information Sciences University of Alabama
2.2. Instantaneous Velocity
2.2. Instantaneous Velocity toc Assuming that your are not familiar with the technical aspects of this section, when you think about it, your knowledge of velocity is limited. In terms of your own mathematical
Gluing things together with Haskell. Neil Mitchell http://nmitchell.co.uk/
Gluing things together with Haskell Neil Mitchell http://nmitchell.co.uk/ Code Elegantly designed Build system Test harness Continuous integration Release bundling Installer generator Release distribution
University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python
Introduction Welcome to our Python sessions. University of Hull Department of Computer Science Wrestling with Python Week 01 Playing with Python Vsn. 1.0 Rob Miles 2013 Please follow the instructions carefully.
Summation Algebra. x i
2 Summation Algebra In the next 3 chapters, we deal with the very basic results in summation algebra, descriptive statistics, and matrix algebra that are prerequisites for the study of SEM theory. You
GENERIC and GIMPLE: A New Tree Representation for Entire Functions
GENERIC and GIMPLE: A New Tree Representation for Entire Functions Jason Merrill Red Hat, Inc. [email protected] 1 Abstract The tree SSA project requires a tree representation of functions for the optimizers
Useful Number Systems
Useful Number Systems Decimal Base = 10 Digit Set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Binary Base = 2 Digit Set = {0, 1} Octal Base = 8 = 2 3 Digit Set = {0, 1, 2, 3, 4, 5, 6, 7} Hexadecimal Base = 16 = 2
Pascal is here expressing a kind of skepticism about the ability of human reason to deliver an answer to this question.
Pascal s wager So far we have discussed a number of arguments for or against the existence of God. In the reading for today, Pascal asks not Does God exist? but Should we believe in God? What is distinctive
Variable Base Interface
Chapter 6 Variable Base Interface 6.1 Introduction Finite element codes has been changed a lot during the evolution of the Finite Element Method, In its early times, finite element applications were developed
Seven Things You Must Know Before Hiring a DUI Lawyer
Seven Things You Must Know Before Hiring a DUI Lawyer 1 Introduction Some people don t quite understand the severity of getting a DUI. In many cases, your license is instantly taken away and you won t
How to Beat Online Roulette!
Martin J. Silverthorne How to Beat Online Roulette! Silverthorne Publications, Inc. How to Beat Online Roulette! COPYRIGHT 2015 Silverthorne Publications Inc. All rights reserved. Except for brief passages
The countdown problem
JFP 12 (6): 609 616, November 2002. c 2002 Cambridge University Press DOI: 10.1017/S0956796801004300 Printed in the United Kingdom 609 F U N C T I O N A L P E A R L The countdown problem GRAHAM HUTTON
Monitors, Java, Threads and Processes
Monitors, Java, Threads and Processes 185 An object-oriented view of shared memory A semaphore can be seen as a shared object accessible through two methods: wait and signal. The idea behind the concept
Easy $100-$150 per Day with CPA offers
Easy $100-$150 per Day with CPA offers by Alex Sol http://extra-paycheck.com/ *You have the right to give this guide out for free and to sell this guide, suggested retail price: $7 ** You do not have the
We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
Lecture 6. Weight. Tension. Normal Force. Static Friction. Cutnell+Johnson: 4.8-4.12, second half of section 4.7
Lecture 6 Weight Tension Normal Force Static Friction Cutnell+Johnson: 4.8-4.12, second half of section 4.7 In this lecture, I m going to discuss four different kinds of forces: weight, tension, the normal
Expected Value. 24 February 2014. Expected Value 24 February 2014 1/19
Expected Value 24 February 2014 Expected Value 24 February 2014 1/19 This week we discuss the notion of expected value and how it applies to probability situations, including the various New Mexico Lottery
OPENING INSTRUCTIONS
OPENING INSTRUCTIONS Members of the Jury: Respective Roles of Jurors and Judge You ve been chosen as jurors for this case, and you ve taken an oath to decide the facts fairly. As we begin the trial, I
How to Overcome the Top Ten Objections in Credit Card Processing
How to Overcome the Top Ten Objections in Credit Card Processing Handling the Top Ten Objections Objection #1 I have a contract That s exactly why I m calling you, you see most people we work with have
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything
Cryptography and Network Security Department of Computer Science and Engineering Indian Institute of Technology Kharagpur
Cryptography and Network Security Department of Computer Science and Engineering Indian Institute of Technology Kharagpur Module No. # 01 Lecture No. # 05 Classic Cryptosystems (Refer Slide Time: 00:42)
So You Want Your LLC to Be An S Corporation February 4, 2008
So You Want Your LLC to Be An S Corporation February 4, 2008 Feed address for Podcast subscription: http://feeds.feedburner.com/edzollarstaxupdate Home page for Podcast: http://ezollars.libsyn.com 2008
INTRODUCING AZURE SEARCH
David Chappell INTRODUCING AZURE SEARCH Sponsored by Microsoft Corporation Copyright 2015 Chappell & Associates Contents Understanding Azure Search... 3 What Azure Search Provides...3 What s Required to
CONTENTS OF DAY 2. II. Why Random Sampling is Important 9 A myth, an urban legend, and the real reason NOTES FOR SUMMER STATISTICS INSTITUTE COURSE
1 2 CONTENTS OF DAY 2 I. More Precise Definition of Simple Random Sample 3 Connection with independent random variables 3 Problems with small populations 8 II. Why Random Sampling is Important 9 A myth,
1 Introduction. 2 An Interpreter. 2.1 Handling Source Code
1 Introduction The purpose of this assignment is to write an interpreter for a small subset of the Lisp programming language. The interpreter should be able to perform simple arithmetic and comparisons
Presentation Phrasebook. Version 1.1
Presentation Phrasebook Version 1.1 Academic English material from English for University. Com Giving a presentation This phrasebook presents useful phrases to help you perform the functions listed below:
Equity Value, Enterprise Value & Valuation Multiples: Why You Add and Subtract Different Items When Calculating Enterprise Value
Equity Value, Enterprise Value & Valuation Multiples: Why You Add and Subtract Different Items When Calculating Enterprise Value Hello and welcome to our next tutorial video here. In this lesson we're
arrays C Programming Language - Arrays
arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)
Term Project: Roulette
Term Project: Roulette DCY Student January 13, 2006 1. Introduction The roulette is a popular gambling game found in all major casinos. In contrast to many other gambling games such as black jack, poker,
Mobile web apps: The best option for business? A whitepaper from mrc
Mobile web apps: The best option for business? A whitepaper from mrc Introduction Mobile apps have finally reached the point where businesses can no longer afford to ignore them. Recent surveys and studies
Seven Things You Must Know Before Hiring a DUI Attorney
Seven Things You Must Know Before Hiring a DUI Attorney Seven Things to Know Before Hiring a DUI Attorney Copyright 2014 SmartWeb Online 1 Introduction Some people don t quite understand the severity of
Good Fast or Low cost marketing
Email Marketing 101 Good Fast or Low cost marketing We ve all heard the old adage about how, when it comes to marketing, you can get what you need done well, delivered quickly or produced inexpensively;
This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers
This Unit: Floating Point Arithmetic CIS 371 Computer Organization and Design Unit 7: Floating Point App App App System software Mem CPU I/O Formats Precision and range IEEE 754 standard Operations Addition
Pseudo code Tutorial and Exercises Teacher s Version
Pseudo code Tutorial and Exercises Teacher s Version Pseudo-code is an informal way to express the design of a computer program or an algorithm in 1.45. The aim is to get the idea quickly and also easy
Engineering Process Software Qualities Software Architectural Design
Engineering Process We need to understand the steps that take us from an idea to a product. What do we do? In what order do we do it? How do we know when we re finished each step? Production process Typical
2 Mathematics Curriculum
New York State Common Core 2 Mathematics Curriculum GRADE GRADE 2 MODULE 3 Topic E: Model Numbers Within 1000 with Place Value Disks 2.NBT.A Focus Standard: 2.NBT.A Understand place value. Instructional
Unit 12: Introduction to Factoring. Learning Objectives 12.2
Unit 1 Table of Contents Unit 1: Introduction to Factoring Learning Objectives 1. Instructor Notes The Mathematics of Factoring Teaching Tips: Challenges and Approaches Additional Resources Instructor
CS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT?
WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT? introduction Many students seem to have trouble with the notion of a mathematical proof. People that come to a course like Math 216, who certainly
Exercise 1: Python Language Basics
Exercise 1: Python Language Basics In this exercise we will cover the basic principles of the Python language. All languages have a standard set of functionality including the ability to comment code,
By Glenn Fleishman. WebSpy. Form and function
Form and function The simplest and really the only method to get information from a visitor to a Web site is via an HTML form. Form tags appeared early in the HTML spec, and closely mirror or exactly duplicate
Decision Logic: if, if else, switch, Boolean conditions and variables
CS 1044 roject 3 Fall 2009 Decision Logic: if, if else, switch, Boolean conditions and variables This programming assignment uses many of the ideas presented in sections 3 through 5 of the Dale/Weems text
Introduction to Python
WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Pre-Algebra Lecture 6
Pre-Algebra Lecture 6 Today we will discuss Decimals and Percentages. Outline: 1. Decimals 2. Ordering Decimals 3. Rounding Decimals 4. Adding and subtracting Decimals 5. Multiplying and Dividing Decimals
