Hume (programming language)
   HOME

TheInfoList



OR:

Hume is a functionally based programming language developed at the
University of St Andrews (Aien aristeuein) , motto_lang = grc , mottoeng = Ever to ExcelorEver to be the Best , established = , type = Public research university Ancient university , endowment ...
and Heriot-Watt University in
Scotland Scotland (, ) is a Countries of the United Kingdom, country that is part of the United Kingdom. Covering the northern third of the island of Great Britain, mainland Scotland has a Anglo-Scottish border, border with England to the southeast ...
since the year 2000. The language name is both an acronym meaning 'Higher-order Unified Meta-Environment' and an honorific to the 18th-century philosopher
David Hume David Hume (; born David Home; 7 May 1711 NS (26 April 1711 OS) – 25 August 1776) Cranston, Maurice, and Thomas Edmund Jessop. 2020 999br>David Hume" ''Encyclopædia Britannica''. Retrieved 18 May 2020. was a Scottish Enlightenment phil ...
. It targets
real-time Real-time or real time describes various operations in computing or other processes that must guarantee response times within a specified time (deadline), usually a relatively short time. A real-time process is generally one that happens in defined ...
embedded systems An embedded system is a computer system—a combination of a computer processor, computer memory, and input/output peripheral devices—that has a dedicated function within a larger mechanical or electronic system. It is ''embedded'' ...
, aiming to produce a design that is both highly abstract, yet which will still allow precise extraction of time and space execution costs. This allows programmers to guarantee the bounded time and space demands of executing programs. Hume combines
functional programming In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that ...
ideas with ideas from
finite state automata A finite-state machine (FSM) or finite-state automaton (FSA, plural: ''automata''), finite automaton, or simply a state machine, is a mathematical model of computation. It is an abstract machine that can be in exactly one of a finite number o ...
. Automata are used to structure communicating programs into a series of "boxes", where each box maps inputs to outputs in a purely functional way using high-level pattern-matching. It is structured as a series of levels, each of which exposes different machine properties.


Design model

The Hume language design attempts to maintain the essential properties and features required by the embedded systems domain (especially for transparent time and space costing) whilst incorporating as high a level of program abstraction as possible. It aims to target applications ranging from simple micro-controllers to complex real-time systems such as
smartphone A smartphone is a portable computer device that combines mobile telephone and computing functions into one unit. They are distinguished from feature phones by their stronger hardware capabilities and extensive mobile operating systems, whic ...
s. This ambitious goal requires incorporating both low-level notions such as interrupt handling, and high-level ones of data structure abstraction etc. Of course such systems will be programmed in widely differing ways, but the language design should accommodate these varying requirements. Hume is a three-layer language: an outer (static) declaration/
metaprogramming Metaprogramming is a programming technique in which computer programs have the ability to treat other programs as their data. It means that a program can be designed to read, generate, analyze or transform other programs, and even modify itself ...
layer, an intermediate coordination layer describing a static layout of dynamic processes and the associated devices, and an inner layer describing each process as a (dynamic) mapping from patterns to expressions. The inner layer is stateless and purely functional. Rather than attempting to apply cost modeling and correctness proving technology to an existing language framework either directly or by altering a more general language (as with e.g. RTSJ), the approach taken by the Hume designers is to design Hume in such a way that formal models and proofs can definitely be constructed. Hume is structured as a series of overlapping language levels, where each level adds expressibility to the expression semantics, but either loses some desirable property or increases the technical difficulty of providing formal correctness/cost models.


Characteristics

The interpreter and compiler versions differ a bit. * the interpreter (concept prover) admits timeout and custom exceptions. * the compiler admits heap and stack cost bounding but exceptions only print the exception name. The coordination system wires ''boxes'' in a
dataflow programming In computer programming, dataflow programming is a programming paradigm that models a program as a directed graph of the data flowing between operations, thus implementing dataflow principles and architecture. Dataflow programming languages share s ...
style. The expression language is
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
-like. The message passing concurrency system remembers JoCaml's Join patterns or Polyphonic C Sharp
chords Chord may refer to: * Chord (music), an aggregate of musical pitches sounded simultaneously ** Guitar chord a chord played on a guitar, which has a particular tuning * Chord (geometry), a line segment joining two points on a curve * Chord ( ...
, but with all channels asynchronous. There is a scheduler built-in that continuously checks pattern-matching through all boxes in turn, putting on hold the boxes that cannot copy outputs to busy input destinations.


Examples


Vending machine

data Coins = Nickel , Dime , Fake; data Drinks = Coffee , Tea; data Buttons = BCoffee , BTea , BCancel; type Int = int 32 ; exception EFakeCoin :: (Int, string) ; show v = v as string ; box coffee in ( coin :: Coins, button :: Buttons, value :: Int ) -- input channels out ( drink_outp :: string, value’ :: Int , refund_outp :: string, display :: string) -- named outputs within 500KB (400B) -- max heap ( max stack) cost bounding handles EFakeCoin, TimeOut, HeapOverflow, StackOverflow match -- * wildcards for unfilled outputs, and unconsumed inputs ( my_coin, *, v) -> let v’ = incrementCredit my_coin v in ( *, v’, *, show v’) -- time bounding (''within x time-unit'') raises TimeOut () , ( *, BCoffee, v) -> (vend Coffee 10 v) within 30s , ( *, BTea, v) -> (vend Tea 5 v) within 30s , ( *, BCancel, v) -> let refund u = "Refund " ++ show u ++ "\n" in ( *, 0, refund v, *) handle EFakeCoin (v, msg) -> ( *, v , *, msg) , TimeOut () -> (*, *, *, "maybe content exhausted, call service!") , HeapOverflow () -> (*, *, *, "error: heap limit exceeded") , StackOverflow () -> (*, *, *, "error: stack limit exceeded") ; incrementCredit coin v = case coin of Nickel -> v + 5 Dime -> v + 10 Fake -> raise EFakeCoin (v, "coin rejected") ; vend drink cost v = if v >= cost then ( serve drink, v - cost, *, "your drink") else ( *, v, *, "money is short of " ++ show (cost - v)) ; serve drink = case drink of Coffee -> "Coffee\n" Tea -> "Tea\n" ; box control in (c :: char) out (coin :: Coins, button:: Buttons) match 'n' -> (Nickel, *) , 'd' -> (Dime, *) , 'f' -> (Fake, *) , 'c' -> (*, BCoffee) , 't' -> (*, BTea) , 'x' -> (*, BCancel) , _ -> (*, *) ; stream console_outp to "std_out" ; stream console_inp from "std_in" ; -- dataflow wire coffee -- inputs (channel origins) (control.coin, control.button, coffee.value’ initially 0) -- -- outputs destinations (console_outp, coffee.value, console_outp, console_outp) ; wire control (console_inp) (coffee.coin, coffee.button) ;


References


Further reading

*{{cite web , first1=Gergely , last1=Patai , first2=Peter , last2=Hanak , year=2007 , title=Embedded Functional Programming in Hume , url=http://sgate.emt.bme.hu/documents/patai/publications/PataiHanakSE2007.pdf , archive-url=https://web.archive.org/web/20161223080800/http://sgate.emt.bme.hu/documents/patai/publications/PataiHanakSE2007.pdf , archive-date=2016-12-23


External links


The Hume Programming Language web site

The Hume Project at Heriot-Watt University

The EmBounded project
Project to certify resource-bounded code in Hume.
Hume and Multicore
Haskell programming language family Functional languages Systems programming languages Embedded systems Articles with example code