Voglio realizzare il stripPrefixBy
seguente funzione:tipi superiori ordinati e impredicativa
-- 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
Ho provato con ImpredicativeTypes
e RankNTypes
, ma senza fortuna. Come posso implementare stripPrefixBy
con il tipo che voglio avere?
Correlato q/a: http://stackoverflow.com/questions/19982295/pragtical-implications-of-runst-vs-unsafeperformio – crockeea