Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Solver.hs
- -- cleaned up with stylish-haskell (hackage)
- -- and https://github.com/tibbe/haskell-style-guide
- -- also, flatten is 'concat', I think
- {-# LANGUAGE FunctionalDependencies #-}
- {-# LANGUAGE MultiParamTypeClasses #-}
- {-# LANGUAGE ScopedTypeVariables #-}
- module Solver
- (Solver,State,Transition)
- where
- class (Show t,Eq t) => Transition t where
- transition :: State s => s -> t -> s
- class (Show s,Eq s) => State s where
- getPossibleTransitions :: Transition t => s -> [t]
- isStateValid :: s -> Bool
- isGoalState :: s -> Bool
- class (State s, Transition t) => Solver s t | s -> t where
- getPossibleNextStates :: s -> [s]
- getPossibleNextStates state =
- filter isStateValid (map transitionFunction possibleTransitions)
- where
- transitionFunction = transition state :: t -> s
- possibleTransitions = getPossibleTransitions state
- isStateVisited :: [s] -> s -> Bool
- isStateVisited visitedStates state =
- any (== state) visitedStates
- getNextFringeStates :: [s] -> [[s]]
- getNextFringeStates = map getPossibleNextStates
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement