今天,当我使用一个小脚本时,我用foldl而不是foldl'.我得到了stack overflow,所以我进口Data.List (foldl')并对此感到满意.这是我的默认工作流程foldl.只需foldl'在懒惰版本评估时使用.
Real World Haskell说我们应该使用foldl'而不是foldl在大多数情况下.Foldr Foldl Foldl'说
通常选择在
foldr和之间foldl'....
但是,如果组合函数在其第一个参数中是惰性的,则
foldl可能会愉快地返回到达foldl'异常的结果.
一个给定的例子:
(?) :: Int -> Int -> Int
_ ? 0 = 0
x ? y = x*y
list :: [Int]
list = [2, 3, undefined, 5, 0]
okey = foldl (?) 1 list
boom = foldl' (?) 1 list
Run Code Online (Sandbox Code Playgroud)
嗯,我很抱歉,但它相当学术,有趣但是学术上的例子.所以我在问,有没有实际使用的例子foldl …
假设我们有方法:
-(instancetype) initWithElements:(id)firstElement, ... NS_REQUIRES_NIL_TERMINATION;
+(instancetype) objWithElements:(id)firstElement, ... NS_REQUIRES_NIL_TERMINATION;
Run Code Online (Sandbox Code Playgroud)
我明白,如何使用可变数量的参数-initWithElements:,但我不明白如何将变量传递-objWithElements:给-initWithElements:.
我的意思是,我想写一些类似的东西:
+(instancetype) objWithElements:(id)firstElement, ... NS_REQUIRES_NIL_TERMINATION {
return [[[self] initWithElements:ELEMENTS] autorelease];
}
Run Code Online (Sandbox Code Playgroud)
它甚至可能吗?
我看到的问题的唯一解决方案是在数组中存储参数并使用将使用给定数组的init对象的辅助方法.
双方cabal install postgresql-libpq-0.9.0.2并
cabal install --reinstall postgresql-libpq-0.9.0.2没有工作
Configuring postgresql-libpq-0.9.0.2...
setup.exe: The program pg_config is required but it could not be found.
cabal: Error: some packages failed to install:
postgresql-libpq-0.9.0.2 failed during the configure step. The exception was:
ExitFailure 1
Run Code Online (Sandbox Code Playgroud)
注意:我在当地
我试图在OS X上使用notify.el,但每次都会出现下一个错误:
Symbol's value as variable is void: dbus-message-type-method-call
Run Code Online (Sandbox Code Playgroud)
emacs --debug-init给出下一个输出:
Debugger entered--Lisp error: (void-variable dbus-message-type-method-call)
dbus-call-method(:session "org.freedesktop.Notifications" "/org/freedesktop/DBus" "org.freedesktop.DBus.Peer" "Ping")
byte-code("\305^H!\203^S^@\306 \n^K\f\307\310^H&^G\202^Z^@\306 \n^K\f\307%?\207" [timeout bus service dbus-path-dbus dbus-interface-peer natnump dbus-call-method "Ping" :timeout] 8)
dbus-ping(:session "org.freedesktop.Notifications")
(and (require (quote dbus) nil t) (dbus-ping :session "org.freedesktop.Notifications"))
(cond ((executable-find "growlnotify") (quote notify-via-growl)) ((and (require (quote dbus) nil t) (dbus-ping :session "org.freedesktop.Notifications")) (defvar notify-id 0 "Current D-Bus notification$
(setq notify-method (cond ((executable-find "growlnotify") (quote notify-via-growl)) ((and (require (quote dbus) nil t) (dbus-ping :session …Run Code Online (Sandbox Code Playgroud) 今天我想解决下一个问题。
假设我们将 typeclassDataWithDefault定义为
class DataWithDefault a where
defaultValue :: a
Run Code Online (Sandbox Code Playgroud)
我们将数据Example定义为
data Example =
Example { field1 :: Text
, field2 :: Text
} deriving (Show)
instance DataWithDefault Example where
defaultValue = Example "Hello" "World"
instance FromJSON Example where
parseJSON (Object v) =
Example <$> v .:? "field1" .!= field1 defaultValue
<*> v .:? "field2" .!= field2 defaultValue
parseJSON _ = mzero
instance ToJSON Example where
toJSON (Example f1 f2) =
object [ "field1" .= f1 …Run Code Online (Sandbox Code Playgroud) 今天我试图连接两个IO字符串,但无法使它工作.
所以,问题是:假设我们拥有s1 :: IO String和s2 :: IO String.如何实现函数(+++) :: IO String -> IO String -> IO String,它(++) :: [a] -> [a] -> [a]与IO String 完全相同?
更一般的问题是如何实现更一般的功能(+++) :: IO a -> IO a -> IO a?或者甚至更一般?
我正在写一个Haskell程序.我创建了一个名为measurement的数据类型,它是一个双精度数组,它看起来像这样:
data Measurement = Measurement [Double] deriving (Show)
Run Code Online (Sandbox Code Playgroud)
我有一个强制转换为Measurement的功能,它需要一个双打列表列表,并将其转换为测量列表.它看起来像这样:
castToMeasurement :: [[Double]] -> [Measurement]
castToMeasurement = map Measurement
Run Code Online (Sandbox Code Playgroud)
但现在我想对双值进行一些操作.那么有没有一种方法可以取消映射到双打数组?因此,当我给它一个Measurement(或测量列表)时,它会将它转换为双打列表(或双列表列表).谢谢!