nTr      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopq  rstuvwxyz{|}~     Printerparsers (injectionprojection pairs) Ha bit of syntactic sugar to avoid hitting the Shift key too many a time The interpreter for printf  It implements Asai'"s accumulator-less alternative to  Danvy's functional unparsing The interpreter for scanf LThe format specification is first-class. One can build format specification  incrementally  This is not the case with OCaml's printf/scanf (where the B format specification has a weird typing and is not first class). Primitive Printer/parsers A better prefixOf function  prefix patt str --> Just str' B if the String patt is the prefix of String str. The result str'  is str with patt removed " Otherwise, the result is Nothing + !"#$Fand the representation of numerals in the SK calculus. The expression  (F FSum :<= Su Zero) is a partial application of the function sum to 1. %$A few examples: SKK as the identity &'GFinally, we demonstrate that our calculus is combinatorially complete, $ by writing the S and K combinators ()(Finally, the standard test -- Fibonacci *+,-.now we tie up the knot /#and define the sum of two numerals )At the type level, this looks as follows 01We introduce the applicative fixpoint combinator 1EThat is all. The rest of the message are the tests. The first one is 6 the type-level equivalent of the following function:  * testb x = and (not x) (not (not x)) 2At the type level, it looks not much differently: 2&and the big-step evaluation function: 3$Commonly, abstraction is held to be `more fundamental' , which is ! reflected in the popular phrase `Lambda-the-Ultimate'. In our system, B application is fundamental. An abstraction is a not-yet-applied E application -- which is in itself a first-class value. The class A E defines the meaning of a function, and an instance of A becomes the $ definition of a function (clause). EWe have dealt with simple expressions and applicative things. We now H build sequences of applications, and define the corresponding big step 6 semantics. We introduce the syntax for applications: 4DThe next function is the boolean And. It takes two arguments, so we  have to handle currying now. 5>The meaning of |A l a b| is that the application to |a| of an - applicable thing denoted by |l| yields |b|. ISurprisingly, this already works. Let us define the boolean Not function 67/Indicator for functions, or applicable things: 89:;<=>First we define some constants ?@ABEWe define the instances of Show to be able to show things. We define 8 the instances in a way that the value is not required. Other particular rules  Familiar rules for applications 6Abstractions are values and so evaluate to themselves !Constants evaluate to themselves GWhen we receive the second argument, we are in the position to produce . the result. Again, we use the case analysis. DApplying And to an argument makes a closure, waiting for the second  argument. by case analysis: / !"#$%&'()*+,-./0123456789:;<=>?@AB#>?<=:;8976543210/.-,+*@)(A'&%$#"B !# !!"#$%&'()*+,-./01234567899:;;<==>??@ABCD%and obtain quite a different result:   *TypeFN> :t test_sspn4 D test_sspn4 :: ((((Bool -> Bool) -> Bool) -> Bool) -> Bool) -> Bool CIn effect, we were able to use not only (a->) but also (->a) as an A unary type function. Moreover, we achieved the latter by almost D literally applying the flip function to the arrow type constructor  (->). FUsing the type inspection tools (typecast), we can replace the family B of functions ATC1, ATC2 with one, kind-polymorphic, polyvariadic D function ATC. This approach will be explained in further messages. DWe can use the computed types to drive overloaded functions such as A read and show. The specifically instantiated read functions, in D particular, will check that a (remotely) received serialized value  matches our expectation. Let'*s consider the type of trees of the depth  of at most N. EFwe make a very little change GFThe comparison of ATC1 with ATC2 shows two different ways of defining  abstractions: as (F x) terms (`lambda-terms' in our calculus) and as A polymorphic types (Haskell type abstractions). The two ways are E profoundly related. The more verbose type application notation, via  (:<=), has its benefits. After we introduce another higher-order  function HITo generalize, JMWe can then write the type of n-ary propositions Prop(N) in a different way, E as an N-times application of the type constructor (Bool->) to Bool. KLKWe introduce the combinator Ntimes: |NTimes f x n| applies f to x n times. ' This is a sort of fold over numerals. M@We can compute types by applying type functions, just as we can G compute values by applying regular functions. Indeed, let us define a D StrangeProp of the kind NAT -> Type. StrangeProp(n) is the type of E propositions of arity m, where m is fib(n). We compose together the F already defined type function Prop2 and the type function Fib in the  previous message. NOP%Our first example comes from Cardelli's paper: defining the type + Prop(n), of n-ary propositions. That is,  9 Prop(2) should be the type Bool -> Bool -> Bool A Prop(3) is the type of functions Bool -> Bool -> Bool -> Bool etc. Cardelli'$s paper (p. 10) writes this type as  "let Prop:: AllKK(N:: NatK) Type = $ recK(F:: AllKK(N:: NatK) Type) J funKK(N:: NatK) caseK N of 0K => Bool; succK(M) => Bool -> F(M);  let and2: Prop(2K) = & fun(a: Bool) fun(b: Bool) a & b; EHere 0K and 2K are type-level numerals of the kind NatK; recK is the G type-level fix-point combinator. The computed type Prop(2) then gives  the type to the term and2. .In our system, this example looks as follows: QGWe can do better, with the help of higher-order type functions. First F we declare a few standard Haskell type constants as constants in our ) calculus, with trivial evaluation rules CDEFGHIJKLMNOPQPONMQLKJIHGFDECCDEEFGHIJKLMNOPQR%The implementation is quite trivial. STUVAThe following instances presume that an exception that occurs in  m6 discard the state accumulated since the beginning of m s execution.  If that is not desired -- don't use StateT. Rather, allocate F IORef and carry that _immutable_ value in a ReaderT. The accumulated ; state will thus persist. One can always use IORefs within  any MonadIO. &The following is almost verbatim from Control.Monad.Error  Section 1MonadError instances for other monad transformers RSTUVTURSVRSSTUUVWBecause DList contains the pointer to the current element, DList  is also a Zipper XYZ[\]^_`a)Representation of the double-linked list bOperations on the DList a c=In a well-formed list, dl_current must point to a valid node / All operations below preserve well-formedness deauxiliary function f/The insert operation below makes a cyclic list  The other operations don't care 4 Insert to the right of the current element, if any : Return the DL where the inserted node is the current one g1Delete the current element from a non-empty list 0 We can handle both cyclic and terminated lists * The right node becomes the current node. B If the right node does not exists, the left node becomes current hijIf no right, just stay inplace klIf no left, just stay inplace mn8The following does not anticipate cycles (deliberately) oReverse taking: we move left pUpdate the current node inplace q@This one watches for a cycle and terminates when it detects one AWXYZ[\]^_`abcdefghijklmnopqa\]^_`WXYZ[bcdefghijklmnopqWXYZ[XYZ[\]^_`]^_`abcdefghijklmnopq         !"#$%&'()*+,-./01234455667789:;<<=>?@ABCDEFGHIJKKLMMNOP<<QRSTUVWXYZ[\]^_`abcdefghijklmnopq   efghijklmnopqrstuvwxyz{|}~liboleg-0.1.0.1Text.PrintScanFText.PrintScanLanguage.TypeLCLanguage.TypeFNControl.CaughtMonadIO Data.FDListFScFPr PrinterParserFormattingSpeclitintcharfpp^fmtsprintfsscanfshowreadprefixF:^FPPFChrFIntFLitintpintsNatfromNatCombTwoCombSuCombZTest_skkCombSCombKFibFib'N3N2N1N0FSumFSum'RecTestbE:<FAndFNotASuZeroHFalseHTruetest_sumtest_fib test_ctwoTreeDNNodeSSPropN'FlipSPropN'ATC2PropN'ATC1Ntimes StrangePropProp2PropProp'oddand4t CaughtMonadIOgcatch MyExceptioncatchDynDList dl_counter dl_currentdl_memnode_val node_left node_rightRefempty well_formedis_empty get_curr_node insert_rightdeleteget_curr move_right move_right' move_left move_left'fromListtakeDL takeDLrevupdatetoListtp1ts1tp2ts2fmt3tp3ts3tp4ts4fmt50fmt5tp5ts5 $fShowHTrue$fESuSu$fE: