Hugs (interpreter)
Template:Short description Template:Notability {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other
Hugs (Haskell User's Gofer System), also Hugs 98, is a bytecode interpreter for the functional programming language Haskell. Hugs is the successor to Gofer, and was originally derived from Gofer version 2.30b.<ref name="Hugs FAQ">{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> Hugs and Gofer were originally developed by Mark P. Jones, now a professor at Portland State University.
Hugs comes with a simple graphics library. As a complete Haskell implementation that is portable and simple to install, Hugs is sometimes recommended for new Haskell users.
Hugs deviates from the Haskell 98 specification<ref name="Revised report">Template:Cite report</ref> in several minor ways.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> For example, Hugs does not support mutually recursive modules. A list of differences exists.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>
The Hugs prompt is a Haskell read–eval–print loop (REPL). It accepts expressions for evaluation, but not module, type, or function definitions. Hugs can load Haskell modules at start-up.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>
ExamplesEdit
Extensible recordsEdit
An example of "typed records with extensibility", a non-standard feature unique to Hugs.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> <syntaxhighlight lang="haskell"> module Main where
import Hugs.Trex
type Coord = Double type Point2D = Rec (x::Coord, y::Coord) type Point3D = Rec (x::Coord, y::Coord, z::Coord)
point2D = (x=1, y=1) :: Point2D
-- emptyRec :: Rec EmptyRow -- predefined
-- (x=1 | (y=1)) -- rec. extension -- (x=v | rec) -- record value decomposition, pattern fields must be non empty -- (x::type | rec) -- record type decomposition
-- (rec\z) in the context means rec does not contain field z
-- add a field z with the same type as field x addZCoord :: (r\z, r\x) => t -> Rec ( x::t | r) -> Rec ( x::t, z::t | r) addZCoord z ( x = x | other) = (x = x, z = z | other)
point3D = addZCoord 3 point2D -- :: Point3D
-- admit any record with showable fields x and y printXY :: (Show t, r\x, r\y) => Rec (x::t, y::t | r) -> IO () printXY point = putStrLn xy
-- with SML style field accessors ('#' prefix) where xy = show (#x point) ++", "++ show (#y point)
incrementX :: (Num t, r\x) => Rec (x::t | r) -> Rec (x::t | r) incrementX (x=v | rest) = (x=v+1 | rest)
main = do
let point3D' = incrementX point3D printXY point2D printXY point3D'
</syntaxhighlight> Running with H98 compatibility turned off to activate language extensions:<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>
runhugs -98 test.hs