最近几周我刚刚开始学习 Haskell。我正在使用 Project Euler 问题来学习,目前正在尝试弄清楚是否有可能。不找人给我答案,只需要帮助理解 Haskell 中的数据结构。
我目前正在处理问题 484,它指定了一个递归函数。编写函数不是问题,我目前有:
import Math.NumberTheory.Primes
import Data.Maybe
import Data.List
derivative :: Integer -> Integer
derivative x
| x < 2 = error "Error: Attempt to evaluate outside domain"
| isPrime x = 1
| otherwise = (derivative a)*b + a*(derivative b)
where
[a, b] = int_split x
--this function find the first pair of divisors
int_split :: Integer -> [Integer]
int_split n = [first_div, n `div` first_div] where
first_div = fromJust $ …Run Code Online (Sandbox Code Playgroud)