cube-hs: High-performance, type-safe Rubik's Cube solver with C FFI bindings.

[ algorithms, data-structures, game, library, mit ] [ Propose Tags ] [ Report a vulnerability ]

A professional Haskell library providing algebraic operations and zero-cost FFI bindings to C solvers for Rubik's Cube.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.4.0.0, 0.4.0.1
Change log CHANGELOG.md
Dependencies array (>=0.5 && <0.6), base (>=4.14 && <5), system-cxx-std-lib (>=1.0 && <1.1), vector-sized (>=1.6.1 && <1.7) [details]
License MIT
Author coshz
Maintainer fsinhx@gmail.com
Uploaded by coshz at 2026-09-17T21:10:51Z
Category Game, Data Structures, Algorithms
Home page https://github.com/coshz/cube
Bug tracker https://github.com/coshz/cube/issues
Distributions
Downloads 0 total (0 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-09-17 [all 1 reports]

Readme for cube-hs-0.4.0.1

[back to package description]

cube-hs

Hackage License: MIT GitHub

A performant and type-safe Rubik's Cube manipulation and permutation library for Haskell.

Features

  • Type-Safe Representation: Strongly typed representations of Cubes, Faces, Turns, and Moves.
  • Algebraic Group Actions: Pure permutation math leveraging Semigroup, Monoid, and the ActsOn typeclass.
  • Flexible Interactions: Turn individual faces, apply sequence moves, or compose transformations seamlessly.

Installation

Add cube-hs to your project's .cabal file dependencies:

build-depends: base >= 4.14 && < 5, cube-hs

Or install it via cabal:

cabal update
cabal install cube-hs

Usage

module Main where

import Data.Cube
import Data.Maybe (fromMaybe)

main :: IO ()
main = do
    -- 1. Inspect solved cube state
    let solvedCube = cubeId
    putStrLn $ "Solved Cube Colors: " ++ showCube solvedCube
    -- "UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB"

    -- 2. Parse standard turn notations
    let turnNotation = "U F U' L2 R L' D2 B"
    let turns = fromMaybe [] $ parseTurns turnNotation
    
    -- 3. Scramble the cube by folding turns
    let scrambledCube = foldl (&>) solvedCube turns
    putStrLn $ "Scrambled Cube:     " ++ showCube scrambledCube

    -- 4. Solve the scrambled cube & verify
    let solution = unsafeSolveFrom scrambledCube
    let restoredCube = applyTurns scrambledCube solution

    if restoredCube == solvedCube
        then putStrLn $ "Solution: " ++ showTurns solution ++ "."
        else putStrLn "Solving failed."