Hume (language)
Encyclopedia
Hume is a functionally-based programming language developed at the University of St Andrews
University of St Andrews
The University of St Andrews, informally referred to as "St Andrews", is the oldest university in Scotland and the third oldest in the English-speaking world after Oxford and Cambridge. The university is situated in the town of St Andrews, Fife, on the east coast of Scotland. It was founded between...

 and Heriot-Watt University
Heriot-Watt University
Heriot-Watt University is a university based in Edinburgh, Scotland. The name commemorates George Heriot, the 16th century financier to King James, and James Watt, the great 18th century inventor and engineer....

 in Scotland
Scotland
Scotland is a country that is part of the United Kingdom. Occupying the northern third of the island of Great Britain, it shares a border with England to the south and is bounded by the North Sea to the east, the Atlantic Ocean to the north and west, and the North Channel and Irish Sea to the...

, and named after the 18th Century philosopher David Hume
David Hume
David Hume was a Scottish philosopher, historian, economist, and essayist, known especially for his philosophical empiricism and skepticism. He was one of the most important figures in the history of Western philosophy and the Scottish Enlightenment...

. It targets real-time
Real-time computing
In computer science, real-time computing , or reactive computing, is the study of hardware and software systems that are subject to a "real-time constraint"— e.g. operational deadlines from event to system response. Real-time programs must guarantee response within strict time constraints...

 embedded systems, aiming to produce a design that is both highly abstract, yet which will still allow precise extraction of time and space execution costs, so allowing programs to be written that will execute under guaranteed bounded time and space constraints.

Hume is unusual in combining functional programming
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

 ideas with ideas from finite state automata. Automata are used to structure communicating programs into a series of "boxes", where each box maps inputs to outputs in a purely functional
Purely functional
Purely functional is a term in computing used to describe algorithms, data structures or programming languages that exclude destructive modifications...

 way using high-level pattern-matching. It is also unusual in being structured as a series of levels, each of which exposes different
machine properties, which is highly unusual.

The Hume 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
Smartphone
A smartphone is a high-end mobile phone built on a mobile computing platform, with more advanced computing ability and connectivity than a contemporary feature phone. The first smartphones were devices that mainly combined the functions of a personal digital assistant and a mobile phone or camera...

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
Metaprogramming is the writing of computer programs that write or manipulate other programs as their data, or that do part of the work at compile time that would otherwise be done at runtime...

 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.

Example


{- example file fibo-i.hume
-}

-- declarations

type Int = int 32 ;

exception EIncredible :: (Int, string) ;
exception EIllegalArgument :: string ;

-- expression language (eager evaluation)

fibo :: Int -> Int ;

fibo 0 = 1;
fibo 1 = 1;
fibo n = if n < 0 then raise EIllegalArgument "fibo: negative argument: " ++ (n as string)
else fibo (n-1) + fibo (n-2);

-- fibo bounded in time

bfibo :: Int -> Int ;
bfibo n = (fibo n) within 10ms ; -- evaluation time restriction
-- raises Timeout (interpreter only)

-- automata as stateless boxes
-- the state is kept by feedback into the mailboxes

box fib
-- tuple of inputs, single element mailboxes
in (n::integer, flag::integer)
-- tuple of named outputs
out (nextn::integer, flag'::integer, result::(integer, integer, string))
-- within 500KB (400KB) -- heap and stack cost boundings (compiler only)
-- would throw HeapOverflow, StackOverflow
handles Timeout, EIncredible, EIllegalArgument -- declares handled exceptions

match
-- pattern for the tuple of inputs -> expression_with_type_of_the_out_tuple
-- * wildcards for unfilled outputs, and unconsumed inputs

(n, 0) -> if n >= 99 then raise EIncredible (n, " reached")
else let calc = bfibo n
in (n+1, 0, (n, calc, "\n"))
| (n, 1) -> (n, 0, (n, *, " Timeout thrown\n"))
| (n, 2) -> (n, 0, (n, *, " EIncredible thrown\n"))

handle

-- exception_pattern -> expression_with_type_of_the_out_tuple

Timeout -> ( 0, 1, (*, *, "Timeout caught, we restart n to 0\n"))
| EIncredible (n, msg) ->
(0, 2, (*, *, "Incredible: " ++ (n as string) ++ msg
++ ", we restart n to 0\n"))
| EIllegalArgument msg -> (0, 0, (*, *, "Illegal argument: " ++ msg ++ "\n"))
-- connections

stream output to "std_out";

wire fib

-- fib in tuple match with origins qualified named outputs and sources

(fib.nextn initially 0, fib.flag' initially 0)

-- fib out tuple match with destination mailboxes and sinks

(fib.n, fib.flag, output)


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK