RSolve: A general solver for equations

[ library, logic, mit, program, unification ] [ Propose Tags ]

A general solver for type checkers of programming languages and real world puzzles with complex constraints.


[Skip to Readme]

Modules

[Last Documentation]

  • RSolve
    • RSolve.BrMonad
    • HM
      • RSolve.HM.Core
    • RSolve.Infr
    • RSolve.Logic
    • Options
      • RSolve.Options.Core

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, 2.0.0.0
Dependencies base (>=4 && <5), containers, RSolve [details]
License MIT
Copyright 2018 thautwarm
Author thautwarm
Maintainer twshere@outlook.com
Category Language
Home page https://github.com/thautwarm/Rsolver#readme
Source repo head: git clone https://github.com/thautwarm/Rsolver.git
Uploaded by ice1000 at 2018-12-25T07:27:53Z
Distributions NixOS:2.0.0.0
Executables RSolveExample
Downloads 1609 total (12 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2018-12-25 [all 3 reports]

Readme for RSolve-0.1.0.0

[back to package description]

RSolve

A general solver for type checkers of programming languages and real world puzzles with complex constraints.

Preview

Here are 2 special cases presented in the following sections to show how powerful RSolve is.

The Most Graceful Hindley-Milner Unification

Check RSolve.HM.Core and RSolve.HM.Example.

Uncomment the code in Main.hs could reproduce following program:

check = do
    let i = Prim Int
    let f = Prim Float
    let arrow = Op Arrow i f
    -- u means undecided
    u1 <- new
    u2 <- new
    u3 <- new
    u4 <- new
    -- u1 -> u2 where u1, u2 is not generic 
    let arrow_var = Op Arrow (Var u1) (Var u2)    
    -- int -> int
    let arrow_inst1 = Op Arrow i i
    -- float -> float
    let arrow_inst2 = Op Arrow f f
    -- a generic function
    let arrow_generic = Forall [u3] $ Op Arrow (Var u3) (Var u3)

    let arrow_match = Op Arrow (Var u4) (Var u4)

    _ <- solve $ Unify arrow arrow_var
    _ <- solve $ Unify arrow_inst1 arrow_match
    _ <- solve $ Unify arrow_generic arrow_inst1
    _ <- solve $ Unify arrow_generic arrow_inst2
    _ <- solveNeg

    mapM require [Var u1, Var u2, arrow_inst1, arrow_inst2, arrow_generic, arrow_match]
  

output:

u1 : Int
u2 : Float
arrow_inst1 : (Int -> Int)
arrow_inst2 : (Float -> Float)
arrow_generic : forall  a2.(a2 -> a2)
arrow_match : (Int -> Int)

N-Option Puzzles

This implememtation is presented at RSolve.Options, which provides the abstractions to solve all kinds of puzzles described with options.

A Hello World program could be found at src/Main.hs which solves a complex problem described with following link:

https://www.zhihu.com/question/68411978/answer/558913247.

However, the much easier cases taking the same background as above problem (logic constraints described with four options A, B, C, D) could be enjoyale:

test2 = do
  a <- store $ sol [A, B, C]
  b <- store $ sol [B, C, D]
  c <- store $ sol [C]
  _ <- solve $ a `eq`  b
  _ <- solve $ b `neq` c
  _ <- solveNeg  -- `Not` condition requires this
  _ <- solvePred -- unnecessary
  mapM require [a, b, c] 
  
main = do
    format ["a", "b", "c"] . nub . L.map fst
    $ runBr test2 emptyLState

output:

λ stack exec RSolve
====
"a" : Sol (fromList [B])
"b" : Sol (fromList [B])
"c" : Sol (fromList [C])