Applicative functors and monads have conquered the world of functional programming by providing general and powerful ways of describing effectful computations using pure functions. Applicative functors provide a way to compose independent effects that cannot depend on values produced by earlier computations, and all of which are declared statically. Monads extend the applicative interface by making it possible to compose dependent effects, where the value computed by one effect determines all subsequent effects, dynamically.This paper introduces an intermediate abstraction called selective applicative functors that requires all effects to be declared statically, but provides a way to select which of the effects to execute dynamically. We demonstrate applications of the new abstraction on several examples, including two industrial case studies.Consider a simple example, where we use the monad f = IO to describe an effectful program that prints "pong" to the terminal if the user enters "ping": pingPongM :: IO () pingPongM = getLine >>= \s -> if s == "ping" then putStrLn "pong" else pure ()The first argument of the bind operator reads a string using getLine :: IO String, and the second argument is the function of type String -> IO (), which prints "pong" when s == "ping".As we will see in sections ğ3 and ğ4, in some applications it is desirable to know all possible effects statically, i.e. before the execution. Alas, this is not possible with monadic effect composition. To inspect the function \s -> ..., we need a string s, which becomes available only during execution. We are therefore unable to predict the effects that pingPongM might perform: instead of conditionally executing putStrLn, as intended, it might delete a file from disk, or launch proverbial missiles.Applicative functors, introduced by McBride and Paterson [2008], can be used for composing statically known collections of effectful computations, as long as these computations are independent from each other. The key ingredient of applicative functors is the apply operator, denoted by <*>:The operator takes two effectful computations, which Ð independently Ð compute values of types a -> b and a, and returns their composition that performs both computations, and then applies the obtained function to the obtained value producing the result of type b. Crucially, both arguments and associated effects are known statically, which, for example, allows us to pre-allocate all necessary computation resources upfront (ğ3) and execute all computations in parallel (ğ4).Our ping-pong example cannot be expressed using applicative functors. Since the two computations must be independent, the best we can do is to print "pong" unconditionally:pingPongA :: IO () pingPongA = fmap (\s -> id) getLine <*> putStrLn "pong"Here we use fmap (\s -> id) to replace the input string s, which we now have no need for, with the identity function id :: () -> (), thus matching the type of putStrLn "pong" :: IO (). We cannot execute the putStrLn "pong" effect conditionally but, on the posit...
This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License Newcastle University ePrints-eprint.ncl.ac.uk
Verification of functional correctness of control programs is an essential task for the development of space electronics; it is difficult and time-consuming and typically outweighs design and programming tasks in terms of development hours. We present a verification approach designed to help spacecraft engineers reduce the effort required for formal verification of low-level control programs executed on custom hardware. The approach uses a metalanguage to describe the semantics of a program as a state transformer, which can be compiled to multiple targets for testing, formal verification, and code generation. The metalanguage itself is embedded in a strongly-typed host language (Haskell), providing a way to prove program properties at the type level, which can shorten the feedback loop and further increase the productivity of engineers.The verification approach is demonstrated on an industrial case study. We present REDFIN, a processing core used in space missions, and its formal semantics expressed using the proposed metalanguage, followed by a detailed example of verification of a simple control program.
scite is a Brooklyn-based organization that helps researchers better discover and understand research articles through Smart Citations–citations that display the context of the citation and describe whether the article provides supporting or contrasting evidence. scite is used by students and researchers from around the world and is funded in part by the National Science Foundation and the National Institute on Drug Abuse of the National Institutes of Health.
customersupport@researchsolutions.com
10624 S. Eastern Ave., Ste. A-614
Henderson, NV 89052, USA
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Copyright © 2024 scite LLC. All rights reserved.
Made with 💙 for researchers
Part of the Research Solutions Family.