我有以下的功能就像一个索引操作: let {
index :: [a]->Int->Maybe a
index [] i = error "Empty list"
index l i = if i <= ((length l) - 1) && i >= 0 then
Just(l !! i)
else
error "Index out
名单,我有以下功能: -- xs: list to be changed
-- ws: list of indices where the values will change to 0
replaceAtIndices xs ws = [if (fromJust (elemIndex x xs)) `elem` ws then 0 else x | x <- xs]
功能发生在2名列表。
在this教程中,我发现下面的代码片段: deposit :: (Num a) => a -> a -> Maybe a
deposit value account = Just (account + value)
withdraw :: (Num a,Ord a) => a -> a -> Maybe a
withdraw value account = if (account < va
你不见于Ger.Offen看到0除了错误处理,例如,因为名单是有点Maybe自己:他们有自己的“Nothing‘:[]和自己的’Just”:(:)。 我用Maybe和函数将标准转换为“实验”列表编写了一个列表类型。 toStd . toExp == id。 data List a = List a (Maybe (List a))
deriving (Eq, Show, Read)
我有一个函数可能会失败,所以它返回的值需要包装在一个Maybe中。它使用另一个也可能失败的函数,这也包含在Maybe中。问题是,为了让类型在中间计算中得到解决,我必须“提前”提升函数以在Maybe语境中工作。这导致我得到一个类型Maybe [也许整数],当我想要的是可能[整数]。有问题的函数是exptDecipherString函数,强制“提前”提升的函数是modularInverse函数。 im