type-variables

    4熱度

    1回答

    (道歉,如果我的術語是錯誤的)。 我想寫處理異常的包裝功能:如果給定IO動作拋出,則返回Nothing(當然是IO上下文中),但如果給定IO行動成功,則返回Just v。 tryMaybe :: IO a -> IO (Maybe a) tryMaybe action = do result <- (try action) :: IO (Either SomeException a)

    56熱度

    3回答

    Eeek! GHCi在我的代碼中找到了Skolems! ... Couldn't match type `k0' with `b' because type variable `b' would escape its scope This (rigid, skolem) type variable is bound by the type signature for

    2熱度

    2回答

    我有這樣的單態代碼: import Data.Array.MArray import Data.Array.IO (IOUArray) import Data.Ix (Ix) push :: IOUArray Int Int -> Int -> [Int] -> IO Int push stack top [] = return top push stack top (k:ks) =

    1熱度

    1回答

    我想在swift中編寫一個幫助函數,它允許更方便地進行排序。以下是我有什麼工作: someArray.sorted({ someGetter($0) < someGetter($1) }) 相反,我還想寫 someArray.sorted(comparing(someGetter)) 我試圖像這樣定義 func comparing<A,B : Equatable>(f: A -> B) -

    2熱度

    3回答

    給定java.lang.reflect.Method。 我可以打電話, final Class<?> returnType = method.getReturnType(); 但是,當我試着打getTypeParameters()與下面的語句, final TypeVariable<Class<?>>[] typeParameters = returnType.getTypeParameter

    0熱度

    2回答

    我有一點點曖昧類型變量的問題。我喜歡haskell,但這實際上我仍然無法處理。 這個問題很簡單,涉及到Text.Printf的printf。由於這個問題是很一般我就但在一些示例代碼:當然 program = do d <- addd 4 8 printf "%d" d addd x y = return (x+y) 中printf的是進口的。然後編譯器給我一個Num和P

    2熱度

    1回答

    鑑於這種代碼 locale A = fixes foo :: "'a" locale B = A + fixes bar :: "'a × 'a" locale C' = A + fixes baz :: "'a" begin sublocale B foo "(foo, baz)". end 我得到 Type unification fai

    10熱度

    1回答

    例如,ParsecT在其定義中有多個類型變量。 newtype ParsecT s u m a = ParsecT {unParser :: forall b . State s u -> (a -> State s u -> ParseError -> m b) -> (ParseError -> m b) ->

    1熱度

    1回答

    在斯威夫特操作定義斯威夫特功能外,?運營商負責Types作爲參數,而不是值: var z = 42? // won't create an Optional<Int> and won't compile var z : Int? = 42 // ? takes Int and give a Optional<Int> 如何創建自己的功能,或在工作類型,而不是運營商的價值?

    6熱度

    1回答

    我偶爾遇到這個問題,最後想問一下是否有一個共同的解決方案或模式。 是否有可能在嵌套上下文引用中創建一個類型變量來自外部上下文的類型?例如, foo :: a -> ... -> .. foo = ... where bar :: a -> ... 現在bar的a比富的a不同。通常情況下,這是我想要的,但偶爾它會讓生活變得困難,我需要讓它們變得一樣。我使用骯髒的技巧來迫使類型檢查者在