Skip to content

Language

konsumlamm edited this page Apr 10, 2026 · 2 revisions

The language is an extended subset of Haskell 2010.

Differences:

  • Kind variables need an explicit forall.
  • Extensions are always enabled, with the only exception being CPP.
  • Data type contexts are not supported.
  • main in the top module given to mhs serves at the program entry point.
  • Many things that should be an error (but which are mostly harmless) are not reported.
  • Text file I/O always uses UTF8, as does the source code.
  • The BangPatterns extension is parsed, but only effective at the a top level let/where.
  • More differences that I don't remember right now.

Mutually recursive modules are allowed the same way as with GHC, using .hs-boot files.

Extensions

The following extensions are supported:

Records

MicroHs implements the record dot extensions, so accessing a field a in record r is written r.a, as well as the usual a r. The former is overloaded and can access any a field, whereas the latter is the usual monomorphic field selector. Updating a field has the usual Haskell syntax r{ a = e }, but the type is overloaded so this can update the a field in any record. The typeclasses HasField and SetField capture this. HasField "name" rec ty expresses that the record type rec has a field name with type ty that can be extracted with getField. SetField "name" rec ty expresses that the record type rec has a field name with type ty that can be set with setField.

Record updates can also update nested fields, e.g., r{ a.b.c = e }. Note that this will not easily work in GHC, since GHC does not fully implement OverloadedRecordUpdate. When GHC decides how to do it, MicroHs will follow suit.

Note that record updates cannot change the type of polymorphic fields.

Standard library modules

This table provides an overview of which standard library modules are report compliant.

Module Report compliant Comment
Prelude yes1 missing catch (as in GHC)
Control.Monad yes1 fail not in Monad (as in GHC)
Data.Array yes part of array-mhs
Data.Bits yes
Data.Char no missing lexLitChar, readLitChar (see commit b7370759bfb726d997ac238123de5ff6d38c4aa5)
Data.Complex yes1 no datatype context, instance (RealFloat a) => Show a
Data.Int yes
Data.Ix yes
Data.List yes
Data.Maybe yes
Data.Ratio yes
Data.Word yes
Foreign yes
Foreign.C yes
Foreign.C.Error yes
Foreign.C.String no missing functions (in particular CWString related)
Foreign.C.Types no missing/wrong instances
Foreign.ForeignPtr no missing FinalizerEnvPtr, newForeignPtrEnv, addForeignPtrFinalizerEnv. finalizeForeignPtr, unsafeForeignPtrToPtr
Foreign.Marshal yes
Foreign.Marshal.Alloc yes
Foreign.Marshal.Array yes
Foreign.Marshal.Error yes1 void :: Functor f => f a -> f ()
Foreign.Marshal.Utils yes
Foreign.Ptr yes freeHaskellFunPtr does nothing
Foreign.StablePtr yes
Foreign.Storable yes
Numeric yes
System.Environment yes
System.Exit yes
System.IO no missing functions2, missing types3, missing IOMode instances
System.IO.Error yes1 renamed catch, try to catchIOError, tryIOError (as in GHC)

1. not quite, but close enough, see comment

2. hFileSize, hSetFileSize, hIsEOF, hGetPosn, hSetPosn, hSeek, hTell, hIsOpen, hIsClosed, hIsReadable, hIsWritable, hIsSeekable, hSetEcho, hGetEcho, hShow, hWaitForInput, hReady, hPrint

3. HandlePosn, SeekMode

Clone this wiki locally