我偶然發現了一個存在於Haskell中的Eval monad和rparStrategy的問題。請考慮下面的代碼: module Main where
import Control.Parallel.Strategies
main :: IO()
main = print . sum . inParallel2 $ [1..10000]
inParallel :: [Double] -
class Eq a where
(==), (/=) :: a -> a -> Bool
x /= y = not (x == y)
x == y = not (x /= y)
deriving instance Eq Bool
我認爲它會產生 instance Eq Bool where
True == True = True
請原諒我下面可能濫用類別理論術語。如果我看起來有一半線索,我會判斷自己非常成功。 我發現自己寫了一系列的類來處理多個類型構造函數的產品。像這樣: import Control.Applicative
-- | RWS monad.
newtype RWS r w s a = RWS {runRWS :: r -> s -> (a, s, w)}
-- | A class for unar
這是一個簡單的函數。它需要一個輸入Int並返回(可能爲空)(Int, Int)對的列表,其中輸入Int是任何對的立方元素的總和。 cubeDecomposition :: Int -> [(Int, Int)]
cubeDecomposition n = [(x, y) | x <- [1..m], y <- [x..m], x^3 + y^3 == n]
where m = trun