Skip to content

Instantly share code, notes, and snippets.

@Lysxia
Created March 9, 2020 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lysxia/da30abac357deb7981412f1faf0d2103 to your computer and use it in GitHub Desktop.
Save Lysxia/da30abac357deb7981412f1faf0d2103 to your computer and use it in GitHub Desktop.
{-# LANGUAGE RankNTypes #-}
module E where
data Variable
data Expression
class HasVar e where
fromVar :: Variable -> e
instance HasVar Variable
instance HasVar Expression
instance Num Expression
data Solver a
instance Functor Solver
instance Applicative Solver
instance Monad Solver
newtype V = V (forall e. HasVar e => e)
variable :: Solver V
variable = undefined
data Definition = (:=) Variable Expression
register :: Definition -> Solver ()
register = undefined
(|:=|) :: Variable -> Expression -> Solver ()
v |:=| e = register (v := e)
infix 1 :=, |:=|
data Equation
(|==|) :: Expression -> Expression -> Equation
(|==|) = undefined
solve :: Equation -> Solver ()
solve = undefined
computation :: Solver ()
computation = do
V x <- variable
V t <- variable
t |:=| x^2 - 1
solve (t |==| 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment