All Projects → haskell-hint → Hint

haskell-hint / Hint

Licence: bsd-3-clause
Runtime Haskell interpreter

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to Hint

Metalang99
A functional language for C99 preprocessor metaprogramming
Stars: ✭ 152 (-17.84%)
Mutual labels:  interpreter
Wasm Micro Runtime
WebAssembly Micro Runtime (WAMR)
Stars: ✭ 2,440 (+1218.92%)
Mutual labels:  interpreter
Monkey Rust
An interpreter for the Monkey programming language written in Rust
Stars: ✭ 174 (-5.95%)
Mutual labels:  interpreter
Wain
WebAssembly implementation from scratch in Safe Rust with zero dependencies
Stars: ✭ 160 (-13.51%)
Mutual labels:  interpreter
Boa
Boa is an embeddable and experimental Javascript engine written in Rust. Currently, it has support for some of the language.
Stars: ✭ 2,509 (+1256.22%)
Mutual labels:  interpreter
Covscript
Covariant Script Interpreter
Stars: ✭ 169 (-8.65%)
Mutual labels:  interpreter
Eval
Eval is a lightweight interpreter framework written in Swift, evaluating expressions at runtime
Stars: ✭ 157 (-15.14%)
Mutual labels:  interpreter
Hscript
Parser and interpreter for Haxe expressions
Stars: ✭ 178 (-3.78%)
Mutual labels:  interpreter
Nf Interpreter
⚙️ nanoFramework Interpreter, CLR, HAL, PAL and reference target boards
Stars: ✭ 168 (-9.19%)
Mutual labels:  interpreter
Fake
嵌入式脚本语言 Lightweight embedded scripting language
Stars: ✭ 172 (-7.03%)
Mutual labels:  interpreter
Monkey
An Interpreter In Go
Stars: ✭ 162 (-12.43%)
Mutual labels:  interpreter
Cosmos
A new logic programming language.
Stars: ✭ 164 (-11.35%)
Mutual labels:  interpreter
Duckscript
Simple, extendable and embeddable scripting language.
Stars: ✭ 169 (-8.65%)
Mutual labels:  interpreter
Cling
The cling C++ interpreter
Stars: ✭ 2,322 (+1155.14%)
Mutual labels:  interpreter
Alchemyvm
WebAssembly Virtual Machine Built In Elixir
Stars: ✭ 176 (-4.86%)
Mutual labels:  interpreter
S
the s shell
Stars: ✭ 158 (-14.59%)
Mutual labels:  interpreter
Pcgr
Personal Cancer Genome Reporter (PCGR)
Stars: ✭ 168 (-9.19%)
Mutual labels:  interpreter
Charly
🐈 The Charly Programming Language | Written by @KCreate
Stars: ✭ 185 (+0%)
Mutual labels:  interpreter
Go.vm
A simple virtual machine - compiler & interpreter - written in golang
Stars: ✭ 178 (-3.78%)
Mutual labels:  interpreter
Symja android library
☕️ Symja - computer algebra language & symbolic math library. A collection of popular algorithms implemented in pure Java.
Stars: ✭ 170 (-8.11%)
Mutual labels:  interpreter

hint Hackage Build Status

This library defines an Interpreter monad within which you can interpret strings like "[1,2] ++ [3]" into values like [1,2,3]. You can easily exchange data between your compiled program and your interpreted program, as long as the data has a Typeable instance.

You can choose which modules should be in scope while evaluating these expressions, you can browse the contents of those modules, and you can ask for the type of the identifiers you're browsing.

It is, essentially, a huge subset of the GHC API wrapped in a simpler API.

Limitations

It is possible to run the interpreter inside a thread, but on GHC 8.8 and below, you can't run two instances of the interpreter simultaneously.

GHC must be installed on the system on which the compiled executable is running.

Example

{-# LANGUAGE LambdaCase, ScopedTypeVariables, TypeApplications #-}
import Control.Exception (throwIO)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Writer (execWriterT, tell)
import Data.Foldable (for_)
import Data.Typeable (Typeable)
import qualified Language.Haskell.Interpreter as Hint

-- |
-- Interpret expressions into values:
--
-- >>> eval @[Int] "[1,2] ++ [3]"
-- [1,2,3]
-- 
-- Send values from your compiled program to your interpreted program by
-- interpreting a function:
--
-- >>> f <- eval @(Int -> [Int]) "\\x -> [1..x]"
-- >>> f 5
-- [1,2,3,4,5]
eval :: forall t. Typeable t
     => String -> IO t
eval s = runInterpreter $ do
  Hint.setImports ["Prelude"]
  Hint.interpret s (Hint.as :: t)

-- |
-- >>> :{
-- do contents <- browse "Prelude"
--    for_ contents $ \(identifier, tp) -> do
--      when ("put" `isPrefixOf` identifier) $ do
--        putStrLn $ identifier ++ " :: " ++ tp
-- :}
-- putChar :: Char -> IO ()
-- putStr :: String -> IO ()
-- putStrLn :: String -> IO ()
browse :: Hint.ModuleName -> IO [(String, String)]
browse moduleName = runInterpreter $ do
  Hint.setImports ["Prelude", "Data.Typeable", moduleName]
  exports <- Hint.getModuleExports moduleName
  execWriterT $ do
    for_ exports $ \case
      Hint.Fun identifier -> do
        tp <- lift $ Hint.typeOf identifier
        tell [(identifier, tp)]
      _ -> pure ()  -- skip datatypes and typeclasses

Check example.hs for a longer example (it must be run from hint's base directory).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].