Advertisement
JoelSjogren

Untitled

Feb 11th, 2021
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. {-# LANGUAGE FlexibleInstances #-}
  2. import Data.Set (Set,elems,cartesianProduct,fromList,empty,insert,singleton,
  3. union,unions)
  4.  
  5. data CombinatorialProblem a = CP
  6. {
  7. bound :: Set a,
  8. close :: Set a -> Set a
  9. }
  10.  
  11. enumerate :: Ord a => CombinatorialProblem a -> Set (Set a)
  12. enumerate cp = iterate' f null (empty, singleton (close cp empty) :: Set (Set a))
  13. where
  14. f (old, new) = (union old new, fromList fresh)
  15. where
  16. fresh = [close cp (insert a s) | a <- elems (bound cp), s <- elems new]
  17.  
  18. iterate' :: ((a,a) -> (a,a)) -> (a -> Bool) -> (a,a) -> a
  19. iterate' f p x = let (x0,x1) = iterate'' x in x0
  20. where
  21. iterate'' x = if p (let (x0,x1) = x in x1) then x else iterate'' (f x)
  22.  
  23.  
  24.  
  25. minimal.hs:12:40: error:
  26. • Couldn't match type ‘a1’ with ‘a’
  27. ‘a1’ is a rigid type variable bound by
  28. an expression type signature:
  29. forall a1. Set (Set a1)
  30. at minimal.hs:12:70-80
  31. ‘a’ is a rigid type variable bound by
  32. the type signature for:
  33. enumerate :: forall a.
  34. Ord a =>
  35. CombinatorialProblem a -> Set (Set a)
  36. at minimal.hs:11:1-59
  37. Expected type: Set (Set a1)
  38. Actual type: Set (Set a)
  39. • In the expression: singleton (close cp empty) :: Set (Set a)
  40. In the third argument of ‘iterate'’, namely
  41. ‘(empty, singleton (close cp empty) :: Set (Set a))’
  42. In the expression:
  43. iterate' f null (empty, singleton (close cp empty) :: Set (Set a))
  44. • Relevant bindings include
  45. f :: (Set (Set a), Set (Set a)) -> (Set (Set a), Set (Set a))
  46. (bound at minimal.hs:14:5)
  47. cp :: CombinatorialProblem a (bound at minimal.hs:12:11)
  48. enumerate :: CombinatorialProblem a -> Set (Set a)
  49. (bound at minimal.hs:12:1)
  50. |
  51. 12 | enumerate cp = iterate' f null (empty, singleton (close cp empty) :: Set (Set a))
  52. |
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement