Haskell function from (a -> [b]) -> [a -> b]

后端 未结 5 2023
有刺的猬
有刺的猬 2021-01-12 14:06

I have a function seperateFuncs such that

seperateFuncs :: [a -> b] -> (a -> [b])
seperateFuncs xs = \\x -> map ($ x) xs
         


        
5条回答
  •  情书的邮戳
    2021-01-12 14:39

    First of all, you can brute-force yourself this function all right:

    joinFuncs f = [\x -> f x !! i | i<-[0..]]
    

    but this is obviously troublesome – the resulting list is always infinite but evaluating the ith element with x only succeds if length(f x) > i.

    To give a "real" solution to

    The question then is there some datatype f which has a function :: (a -> f b) -> f (a -> b)?

    Consider (->)c. With that, your signature reads (a -> (c->b)) -> (c->(a->b)) or equivalently (a -> c -> b) -> c -> a -> b which, it turns out, is just flip.

    Of course, this is a bit of a trivial one since seperateFuncs has the same signature for this type...

提交回复
热议问题