Tôi muốn thực hiện các chức năng stripPrefixBy
sau:xếp hạng cao hơn và impredicative loại
-- psuedo code signature
stripPrefixBy :: forall a. [forall b. a -> Maybe b] -> [a] -> Maybe [a]
stripPrefixBy [] xs = Just xs
stripPrefixBy _ [] = Nothing
stripPrefixBy (p:ps) (x:xs) = case p x of
Just _ -> stripPrefixBy ps xs
Nothing -> Nothing
res :: Maybe String
res = stripPrefixBy [const (Just 0), Just] "abc"
wantThisToBeTrue :: Bool
wantThisToBeTrue = case res of
Just "c" -> True
_ -> False
Tôi đã cố gắng sử dụng ImpredicativeTypes
và RankNTypes
nhưng không may mắn. Làm thế nào tôi có thể thực hiện stripPrefixBy
với loại tôi muốn nó có?
Liên quan q/a: http://stackoverflow.com/questions/19982295/practical-implications-of-runst-vs-unsafeperformio – crockeea