Advertisement
jckuri

Problem with Solver.hs

Feb 13th, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Solver.hs
  2. {-# LANGUAGE GADTs,FlexibleInstances,UndecidableInstances,ScopedTypeVariables,TypeFamilies,MultiParamTypeClasses #-}
  3.  
  4. module Solver
  5. (Solver,State,Transition)
  6. where
  7.  
  8. class (Show t,Eq t) => Transition t where
  9.  transition :: State s => s -> t -> s
  10.  
  11. class (Show s,Eq s) => State s where
  12.  getPossibleTransitions :: Transition t => s -> [t]
  13.  isStateValid :: s -> Bool
  14.  isGoalState :: s -> Bool
  15.  
  16. class Solver s t where
  17.  getPossibleNextStates :: s -> [s]
  18.  isStateVisited :: [s] -> s -> Bool
  19.  getNextFringeStates :: [s] -> [[s]]
  20.  --getNextGeneration :: [s] -> [s] -> [s]
  21.  
  22. flatten :: [[a]] -> [a]
  23. flatten [] = []
  24. flatten listOfLists = (head listOfLists) ++ (flatten (tail listOfLists))
  25.  
  26. instance (State s,Transition t) => Solver s t where
  27.  
  28.  getPossibleNextStates (state::s) =
  29.   filter isStateValid (map transitionFunction possibleTransitions)
  30.   where
  31.    transitionFunction = (transition state)::(t -> s)
  32.    possibleTransitions = (getPossibleTransitions state)::([t])
  33.  
  34.  isStateVisited visitedStates state =
  35.   any (== state) visitedStates
  36.  
  37.  getNextFringeStates (states::[s]) =
  38.   map (getPossibleNextStates :: (s -> [s])) (states::[s])
  39.  
  40. -- COMPILATION:
  41. {-
  42. Prelude> :l Solver.hs
  43. [1 of 1] Compiling Solver           ( Solver.hs, interpreted )
  44.  
  45. Solver.hs:38:8:
  46.     Ambiguous type variable `t0' in the constraint:
  47.       (Transition t0) arising from a use of `getPossibleNextStates'
  48.     Probable fix: add a type signature that fixes these type variable(s)
  49.     In the first argument of `map', namely
  50.       `(getPossibleNextStates :: s -> [s])'
  51.     In the expression:
  52.       map (getPossibleNextStates :: s -> [s]) (states :: [s])
  53.     In an equation for `getNextFringeStates':
  54.         getNextFringeStates (states :: [s])
  55.           = map (getPossibleNextStates :: s -> [s]) (states :: [s])
  56. Failed, modules loaded: none.
  57. -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement