Advertisement
Guest User

Untitled

a guest
Jan 18th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. let fs = [(+2), (*2), (^2)]
  2. let cs = concat $ map subsequences $ permutations fs
  3. nub cs
  4.  
  5. <interactive>:31:1:
  6. No instance for (Eq (Integer -> Integer))
  7. arising from a use of `nub'
  8. Possible fix:
  9. add an instance declaration for (Eq (Integer -> Integer))
  10. In the expression: nub cs
  11. In an equation for `it': it = nub cs
  12.  
  13. > let fs = [AddTwo, Double, Square]
  14. > let css = nub $ concat $ map subsequences $ permutations fs
  15.  
  16. > css
  17.  
  18. [[],[AddTwo],[Double],[AddTwo,Double],[Square],[AddTwo,Square],[Double,Square],[AddTwo,Double,Square],[Double,AddTwo],[Double,AddTwo,Square],[Square,Double],[Square,AddTwo],[Square,Double,AddTwo],[Double,Square,AddTwo],[Square,AddTwo,Double],[AddTwo,Square,Double]]
  19.  
  20. > map (cs-> call <$> cs <*> [3,4]) css
  21.  
  22. [[],[5,6],[6,8],[5,6,6,8],[9,16],[5,6,9,16],[6,8,9,16],[5,6,6,8,9,16],[6,8,5,6],[6,8,5,6,9,16],[9,16,6,8],[9,16,5,6],[9,16,6,8,5,6],[6,8,9,16,5,6],[9,16,5,6,6,8],[5,6,9,16,6,8]]
  23.  
  24. data Function = AddTwo | Double | Square deriving Eq
  25.  
  26. call AddTwo = (+2)
  27. call Double = (*2)
  28. call Square = (^2)
  29.  
  30. {-# LANGUAGE FlexibleInstances #-}
  31. {-# LANGUAGE NoMonomorphismRestriction #-}
  32.  
  33. data NumResLog a = NRL { runNumRes :: a, runNumResLog :: String }
  34. deriving (Eq, Show)
  35.  
  36. instance (Num a) => Num (NumResLog a) where
  37. fromInteger n = NRL (fromInteger n) (show n)
  38. NRL a alog + NRL b blog
  39. = NRL (a+b) ( "("++alog++ ")+(" ++blog++")" )
  40. NRL a alog * NRL b blog
  41. = NRL (a*b) ( "("++alog++ ")*(" ++blog++")" )
  42. ...
  43.  
  44.  
  45. instance (Num a) => Eq (NumResLog a -> NumResLog a) where
  46. f == g = runNumResLog (f arg) == runNumResLog (g arg)
  47. where arg = NRL 0 "THE ARGUMENT"
  48.  
  49. unlogNumFn :: (NumResLog a -> NumResLog c) -> (a->c)
  50. unlogNumFn f = runNumRes . f . (`NRL`"")
  51.  
  52. > let fs = [(+2), (*2), (^2)]
  53. > let cs = concat $ map subsequences $ permutations fs
  54. > let ncs = map (map unlogNumFn) $ nub cs
  55. > map (map ($ 1)) ncs
  56. [[],[3],[2],[3,2],[1],[3,1],[2,1],[3,2,1],[2,3],[2,3,1],[1,2],[1,3],[1,2,3],[2,1,3],[1,3,2],[3,1,2]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement