我有一個函數正在執行某些特定數據類型的工作。我想知道我能不能把它變成一般人。下面是它的標誌性的通用版本: f :: Monad m => ((a -> b) -> c -> d) -> (a -> m b) -> m c -> m d
如果以上不能寫,或許更受限制的版本可以? f2 :: Monad m => ((a -> a) -> b -> b) -> (a -> m a) -> m b
鑑於年底追加: mangle :: String -> String
,我想要做的事,如: mangle xs = head xs -- works if you change typesig to [a] -> a
但: mangle xs = tail xs ++ head xs -- won't work at all!
會喜歡在列表末尾添加列表的第一個字符,切割第一個字符。
我正在嘗試爲項目的Haskell分配運行ghci。然而,它給了我此錯誤消息: /usr/local/haskell/ghc-8.2.1-x86_64/lib/ghc-8.2.1/bin/ghc: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or d
剛剛遇到了一件對我來說似乎很陌生的東西。反引號的功能類似於句法操作符。 applyOp :: Int -> (Int -> Int -> Int) -> Int -> Int
applyOp x op y = x `op` y
> applyOp 2 (+) 5
7
我很驚訝地看到這一點。我一直認爲反引號需要包圍一個運營商符號或標識符,而不是一個可以在執行過程中綁定到運營商的標識符。我
所以我需要在Haskell中創建一個Set數據類型。 所以,我的問題的第一部分,我需要定義 type Set a = ...
我把它設置爲 type Set a = Set [a]
因爲套裝也只是α的名單,對不對? 或者,將正確的方式做到這一點是 type Set a = ([a])
然後,在接下來的一部分,我需要實現的功能 setSuchThat :: (a -> Bool) ->