Skip to content

Instantly share code, notes, and snippets.

@echatav
Last active August 29, 2015 14:25
Show Gist options
  • Save echatav/988d391a7bc3d53ade1b to your computer and use it in GitHub Desktop.
Save echatav/988d391a7bc3d53ade1b to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleContexts , ScopedTypeVariables , TypeFamilies #-}
import Data.Proxy
class Problem p where
type State p :: *
data Action p :: *
actions :: State p -> [Action p]
result :: State p -> Action p -> State p
successor :: State p -> [(Action p,State p)]
successor s = map (\a -> (a, (result s a))) $ actions s
goal :: Proxy p -> State p
goal = undefined
isGoal :: (Problem p , Eq (State p)) => State p -> Bool
isGoal s = s == goal (Proxy :: Proxy p)
data MovingRobot = MovingRobot
instance Problem MovingRobot where
type State MovingRobot = Int
data Action MovingRobot = SLIDE_LEFT | SLIDE_RIGHT deriving (Show,Ord,Eq)
actions x | x > goal (Proxy :: Proxy MovingRobot) = [SLIDE_LEFT]
| x < goal (Proxy :: Proxy MovingRobot) = [SLIDE_RIGHT]
| otherwise = []
goal (Proxy :: Proxy MovingRobot) = 0
result x SLIDE_LEFT = (x - 1)
result x SLIDE_RIGHT = (x + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment