gym-hs: Haskell bindings for OpenAI Gymnasium

[ ai, library, machine-learning, mit, program, reinforcement-learning ] [ Propose Tags ] [ Report a vulnerability ]

A Haskell library that provides bindings to OpenAI Gymnasium environments. This library enables you to call any Gymnasium environment from Haskell code with a simple, type-safe API. It uses subprocess-based communication to interface with Python's Gymnasium library, providing full access to the rich ecosystem of reinforcement learning environments.

A full example using Gymnasium to implement a DQN solving CartPole is here: https://github.com/Xodarap/hs-gym-example


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1
Change log CHANGELOG.md
Dependencies aeson (>=2.0 && <2.3), base (>=4.7 && <5), bytestring (>=0.10 && <0.13), containers (>=0.6 && <0.8), gym-hs, process (>=1.6 && <1.7), scientific (>=0.3 && <0.4), text (>=1.2 && <2.2), unordered-containers (>=0.2 && <0.3), vector (>=0.12 && <0.14) [details]
Tested with ghc ==9.6.7
License MIT
Copyright 2025 Ben West
Author Ben West
Maintainer xodarap00@gmail.com
Category AI, Machine Learning, Reinforcement Learning
Home page https://github.com/Xodarap/haskell-gymnasium
Bug tracker https://github.com/Xodarap/haskell-gymnasium/issues
Source repo head: git clone https://github.com/Xodarap/haskell-gymnasium
Uploaded by benthamite at 2025-07-25T20:26:15Z
Distributions
Executables gym-hs-example
Downloads 5 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2025-07-25 [all 1 reports]

Readme for gym-hs-0.1.0.1

[back to package description]

Haskell Gymnasium

A Haskell library that provides bindings to OpenAI Gymnasium environments, enabling you to call any Gymnasium environment from Haskell. Implemented by spawning a python subprocess and using stdio to communicate with it.

Quick Start

Building

cabal build

Running the Example

cabal run gym-hs-example

This will create a CartPole-v1 environment and run 5 random steps.

Running Tests

cabal test

Usage Example

{-# LANGUAGE OverloadedStrings #-}
import Data.Aeson (Value(Number))
import Gym.Environment
import Gym.Core

main :: IO ()
main = do
  result <- makeEnv "CartPole-v1"
  case result of
    Left err -> print err
    Right env -> do
      -- Reset environment
      resetResult <- reset env
      case resetResult of
        Left err -> print err
        Right (Observation obs) -> do
          putStrLn $ "Initial observation: " ++ show obs
          
          -- Take an action (0 = left, 1 = right for CartPole)
          stepResult <- step env (Action (Number 0))
          case stepResult of
            Left err -> print err
            Right result -> do
              putStrLn $ "Reward: " ++ show (stepReward result)
              putStrLn $ "Done: " ++ show (stepTerminated result)
      
      -- Clean up
      closeEnv env

A full example using Gymnasium to implement a DQN solving CartPole is here.