Advertisement
Guest User

Untitled

a guest
Feb 13th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Solver.hs
  2. {-# LANGUAGE FunctionalDependencies #-}
  3. {-# LANGUAGE MultiParamTypeClasses  #-}
  4. {-# LANGUAGE ScopedTypeVariables    #-}
  5.  
  6. module Solver
  7.     (Solver,State,Transition)
  8.   where
  9.  
  10. class (Show t,Eq t) => Transition t where
  11.     transition :: State s => s -> t -> s
  12.  
  13. class (Show s,Eq s) => State s where
  14.     getPossibleTransitions :: Transition t => s -> [t]
  15.     isStateValid :: s -> Bool
  16.     isGoalState  :: s -> Bool
  17.  
  18. class (State s, Transition t) => Solver s t | s -> t where
  19.     getPossibleNextStates :: s -> [s]
  20.     getPossibleNextStates state =
  21.        filter isStateValid (map transitionFunction possibleTransitions)
  22.       where
  23.        transitionFunction  = transition state :: t -> s
  24.        possibleTransitions = getPossibleTransitions state
  25.  
  26.     isStateVisited        :: [s] -> s -> Bool
  27.     isStateVisited visitedStates state =
  28.        any (== state) visitedStates
  29.  
  30.     getNextFringeStates :: [s] -> [[s]]
  31.     getNextFringeStates = map getPossibleNextStates
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement