Hugs (interpreter)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Widefox (talk | contribs) at 20:51, 16 September 2018 (→‎External links: destub). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Hugs 98
Developer(s)Mark P. Jones, others
Stable release
September 2006 / September 21, 2006 (2006-09-21)
Operating systemCross-platform
TypeCompiler
LicenseBSD
WebsiteHugs 98 homepage

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.[2] 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[3] in several minor ways.[4] For example, Hugs does not support mutually recursive modules. A list of differences exists.[5]

The Hugs prompt (a Haskell REPL) accepts expressions for evaluation, but not module, type or function definitions. Hugs can load Haskell modules at start-up.[6]

Examples

Extensible records

An example of "Typed records with extensibility", a non standard feature unique to Hugs.[7]

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'

Running with H98 compatibility turned off to activate language extensions:[8]

runhugs -98 test.hs

References

  1. ^ "Hugs 98". www.haskell.org.
  2. ^ "Frequently Asked Questions about Hugs". Retrieved 2006-08-04.
  3. ^ Simon Peyton Jones (editor) (December 2002). "Haskell 98 Language and Libraries: The Revised Report". Retrieved 2006-08-03. {{cite web}}: |author= has generic name (help)
  4. ^ "Haskell 98 non-compliance". The Hugs 98 User's Guide. Retrieved 2006-08-04.
  5. ^ "List of differences with H98 standard".
  6. ^ "Loading and editing Haskell module files". The Hugs 98 User's Guide. Retrieved 2006-08-04.
  7. ^ "Hugs-specific language extensions". www.haskell.org.
  8. ^ "Changing the behaviour of Hugs". www.haskell.org.

External links