Hume (programming language): Difference between revisions

Content deleted Content added
Example: correction
m compound modifier
 
(76 intermediate revisions by 29 users not shown)
Line 1:
{{Short description|Functional programming language}}
{{Orphan|date=February 2009}}
{{Use dmy dates|date=June 2023}}
[[Image:HumeStatue-Edinburgh2006.gif|thumb|Hume Statue in Edinburgh]]
{{Use British English|date=June 2023}}
'''Hume''' is a functionally-based programming language developed at the [[University of St Andrews]] and [[Heriot-Watt University]] in [[Scotland]], and named after the 18th Century philosopher [[David Hume]]. It targets [[real-time computing|real-time]] [[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.
{{More citations needed|date=April 2022}}
{{Infobox programming language
| name = Hume
| logo = <!-- Filename only -->
| logo caption =
| screenshot = <!-- Filename only -->
| screenshot caption =
| sampleCode =
| paradigm = [[Functional programming|Functional]]
| family = [[Haskell]]
| designer = Greg Michaelson<br/>Andrew Ireland<br/>Andy Wallace
| developers = [[University of St Andrews]]<br/>[[Heriot-Watt University]]
| released = {{Start date and age|2000}}
| latest release version = 0.8
| latest release date = {{Start date and age|2008|04|25|df=yes}}
| typing = [[Type inference|Inferred]], [[Static typing|static]], [[Strong and weak typing|strong]]
| scope =
| programming language =
| platform = [[IA-32]], [[PowerPC]]
| operating system = [[macOS]], [[Red Hat]] [[Linux]]
| license =
| file ext =
| file format = <!-- or: | file formats = -->
| website = <!-- {{URL|www.example.com}} -->
| implementations =
| dialects =
| influenced by = [[Haskell]]
| influenced =
}}
[[File:HumeStatue-Edinburgh2006.jpg|thumb|Hume Statue in Edinburgh]]
 
'''Hume''' is a functionally based programming language developed at the [[University of St Andrews]] and [[Heriot-Watt University]] in [[Scotland]] 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]]. It targets [[real-time computing]] [[embedded system]]s, aiming to produce a design that is both highly abstract, and yet allows precise extraction of time and space execution costs. This allows guaranteeing the bounded time and space demands of executing programs.
Hume is unusual in combining [[functional programming]] 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]] 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.
 
Hume combines [[functional programming]] ideas with ideas from [[finite-state automata]]. Automata are used to structure communicating programs into a series of "boxes", where each box maps [[Input/output|inputs to outputs]] in a [[pure function|purely functional]] way using high-level pattern-matching. It is structured as a series of levels, each of which exposes different machine properties.
== The Hume Design Model ==
 
== 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]]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.
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 [[microcontroller]]s to complex real-time systems such as [[smartphone]]s. This ambitious goal requires incorporating both low-level notions such as [[interrupt]] handling, and high-level ones of [[data structure]] abstraction etc. Such systems are programmed in widely differing ways, but the language design should accommodate such varying requirements.
 
Hume is a three-layer language: an outer (static) declaration/[[metaprogramming]] 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.
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.<ref>{{Cite book |last=Eekelen |first=Marko Van |date=2007 |url=https://books.google.com/books?id=p0yV1sHLubcC |title=Trends in Functional Programming |publisher=Intellect Books |isbn=978-1-84150-176-5 |pages=198 |language=en}}</ref>
 
== ExampleCharacteristics ==
The interpreter and compiler versions differ a bit.
<source lang="haskell">
* the interpreter (concept prover) admits timeout and custom exceptions.
{- example file fibo-i.hume
* the compiler admits heap and stack cost bounding but exceptions only print the exception name.
-}
 
The coordination system wires ''boxes'' in a [[dataflow programming]] style.
-- declarations
 
The expression language is [[Haskell]]-like.
type Int = int 32 ;
 
The message passing concurrency system remembers [[JoCaml]]'s [[join-pattern]]s or [[Polyphonic C Sharp]] [[Chord (concurrency)|chords]], but with all channels asynchronous.
exception EIncredible :: (Int, string) ;
exception EIllegalArgument :: string ;
 
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.
-- expression language (eager evaluation)
 
== Examples ==
fibo :: Int -> Int ;
=== Vending machine ===
<syntaxhighlight lang="haskell">
data Coins = Nickel | Dime | Fake;
data Drinks = Coffee | Tea;
data Buttons = BCoffee | BTea | BCancel;
 
fibotype 0Int = 1int 32 ;
fibo 1 = 1;
fibo n = if n < 0 then raise EIllegalArgument "fibo: negative argument: " ++ (n as string)
else fibo (n-1) + fibo (n-2);
 
exception EFakeCoin :: (Int, string) ;
-- fibo bounded in time
 
bfiboshow ::v Int= ->v Intas string ;
bfibo n = (fibo n) within 10ms ; -- restricted to 10 ms.
box coffee
-- raises Timeout () (interpret only)
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
-- automata as stateless boxes
handles EFakeCoin, TimeOut, HeapOverflow, StackOverflow
-- 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_of_type_of_the_''out''_tuple
-- * wildcards for unfilled outputs, and unconsumed inputs
( my_coin, *, v) {- ''join-pattern'' equivalent: coin(my_coin) & value(v) -}
-> let v’ = incrementCredit my_coin v
in ( *, v’, *, show v’)
-- time bounding (''within x time-unit'') raises TimeOut ()
| ( *, BCoffee, v) {- ''join-pattern'' equivalent: button(BCoffee) & value(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
(n, 0) -> if n >= 99 then raise EIncredible (n, " reached")
EFakeCoin (v, msg) else-> (n+1, 0*, (nv , bfibo n*, "\n")msg)
| (n, 1TimeOut () -> (n*, 0, (n*, *, "maybe Timeoutcontent thrown\nexhausted, call service!"))
| HeapOverflow (n, 2) -> (n*, 0, (n*, *, "error: EIncredibleheap thrown\nlimit exceeded"))
| StackOverflow () -> (*, *, *, "error: stack limit exceeded")
;
 
incrementCredit coin v =
handle
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
-- exception_pattern -> expression_of_type_of_the_''out''_tuple
 
wire coffee
Timeout () -> ( 0, 1, (*, *, "Timeout caught, we restart n to 0\n"))
-- inputs (channel origins)
| EIncredible (n, msg) ->
(control.coin, control.button, coffee.value’ initially 0) --
(0, 2, (*, *, "Incredible: " ++ (n as string) ++ msg
-- outputs destinations
++ ", we restart n to 0\n"))
(console_outp, coffee.value, console_outp, console_outp)
| EIllegalArgument msg -> (0, 0, (*, *, "Illegal argument: " ++ msg ++ "\n"))
;
wire control
(console_inp)
(coffee.coin, coffee.button)
;
</syntaxhighlight>
 
==References==
-- connections
{{Reflist}}
 
==Further reading==
stream output to "std_out";
*{{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}}
 
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)
;
</source>
 
== External links ==
* [https://web.archive.org/web/20120722084226/http://www-fp.cs.st-andrews.ac.uk/hume/index.shtml The Hume Programming Language web site]
 
* [http://www.hume-lang.org The Hume Language Web Site]
* [http://www.macs.hw.ac.uk/~greg/hume/ The Hume Project at Heriot-Watt University]
* [https://web.archive.org/web/20190403192341/https://www.embounded.org/ EmBounded project], certifies resource-bounded code in Hume
* [http://www.inf.bme.hu/fp4es/papers/PataiHanakSE2007Presentation.ppt Embedded Functional Programming in Hume]
* [https://glew.org/damp2006/Hume-Multicore.pdf Hume and Multicore]
* [http://embounded.org/ The EmBounded project] Project to certify resource-bounded code in Hume.
 
* [http://glew.org/damp2006/Hume-Multicore.ppt Hume and Multicore]
{{Haskell programming}}
 
[[Category:Haskell programming language family]]
Line 102 ⟶ 165:
[[Category:Systems programming languages]]
[[Category:Embedded systems]]
[[Category:Articles with example code]]
 
[[ca:Hume (llenguatge de programació)]]