SHOW:
|
|
- or go back to the newest paste.
1 | -- Solver.hs | |
2 | -- cleaned up with stylish-haskell (hackage) | |
3 | -- and https://github.com/tibbe/haskell-style-guide | |
4 | -- also, flatten is 'concat', I think | |
5 | ||
6 | {-# LANGUAGE FunctionalDependencies #-} | |
7 | {-# LANGUAGE MultiParamTypeClasses #-} | |
8 | {-# LANGUAGE ScopedTypeVariables #-} | |
9 | ||
10 | module Solver | |
11 | (Solver,State,Transition) | |
12 | where | |
13 | ||
14 | class (Show t,Eq t) => Transition t where | |
15 | transition :: State s => s -> t -> s | |
16 | ||
17 | class (Show s,Eq s) => State s where | |
18 | getPossibleTransitions :: Transition t => s -> [t] | |
19 | isStateValid :: s -> Bool | |
20 | isGoalState :: s -> Bool | |
21 | ||
22 | class (State s, Transition t) => Solver s t | s -> t where | |
23 | getPossibleNextStates :: s -> [s] | |
24 | getPossibleNextStates state = | |
25 | filter isStateValid (map transitionFunction possibleTransitions) | |
26 | where | |
27 | transitionFunction = transition state :: t -> s | |
28 | possibleTransitions = getPossibleTransitions state | |
29 | ||
30 | isStateVisited :: [s] -> s -> Bool | |
31 | isStateVisited visitedStates state = | |
32 | any (== state) visitedStates | |
33 | ||
34 | getNextFringeStates :: [s] -> [[s]] | |
35 | getNextFringeStates = map getPossibleNextStates |