Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let fs = [(+2), (*2), (^2)]
- let cs = concat $ map subsequences $ permutations fs
- nub cs
- <interactive>:31:1:
- No instance for (Eq (Integer -> Integer))
- arising from a use of `nub'
- Possible fix:
- add an instance declaration for (Eq (Integer -> Integer))
- In the expression: nub cs
- In an equation for `it': it = nub cs
- > let fs = [AddTwo, Double, Square]
- > let css = nub $ concat $ map subsequences $ permutations fs
- > css
- [[],[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]]
- > map (cs-> call <$> cs <*> [3,4]) css
- [[],[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]]
- data Function = AddTwo | Double | Square deriving Eq
- call AddTwo = (+2)
- call Double = (*2)
- call Square = (^2)
- {-# LANGUAGE FlexibleInstances #-}
- {-# LANGUAGE NoMonomorphismRestriction #-}
- data NumResLog a = NRL { runNumRes :: a, runNumResLog :: String }
- deriving (Eq, Show)
- instance (Num a) => Num (NumResLog a) where
- fromInteger n = NRL (fromInteger n) (show n)
- NRL a alog + NRL b blog
- = NRL (a+b) ( "("++alog++ ")+(" ++blog++")" )
- NRL a alog * NRL b blog
- = NRL (a*b) ( "("++alog++ ")*(" ++blog++")" )
- ...
- instance (Num a) => Eq (NumResLog a -> NumResLog a) where
- f == g = runNumResLog (f arg) == runNumResLog (g arg)
- where arg = NRL 0 "THE ARGUMENT"
- unlogNumFn :: (NumResLog a -> NumResLog c) -> (a->c)
- unlogNumFn f = runNumRes . f . (`NRL`"")
- > let fs = [(+2), (*2), (^2)]
- > let cs = concat $ map subsequences $ permutations fs
- > let ncs = map (map unlogNumFn) $ nub cs
- > map (map ($ 1)) ncs
- [[],[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