tacit-programming

How to filter a list in J?

限于喜欢 提交于 2019-11-29 06:07:08
问题 I'm currently learning the fascinating J programming language, but one thing I have not been able to figure out is how to filter a list. Suppose I have the arbitrary list 3 2 2 7 7 2 9 and I want to remove the 2s but leave everything else unchanged, i.e., my result would be 3 7 7 9 . How on earth do I do this? 回答1: The short answer 2 (~: # ]) 3 2 2 7 7 2 9 3 7 7 9 The long answer I have the answer for you, but before you should get familiar with some details. Here we go. Monads, dyads There

What does (f .) . g mean in Haskell?

泪湿孤枕 提交于 2019-11-26 14:23:58
I have seen a lot of functions being defined according to the pattern (f .) . g . For example: countWhere = (length .) . filter duplicate = (concat .) . replicate concatMap = (concat .) . map What does this mean? The dot operator (i.e. (.) ) is the function composition operator. It is defined as follows: infixr 9 . (.) :: (b -> c) -> (a -> b) -> a -> c f . g = \x -> f (g x) As you can see it takes a function of type b -> c and another function of type a -> b and returns a function of type a -> c (i.e. which applies the first function to the result of the second function). The function

What does (f .) . g mean in Haskell?

非 Y 不嫁゛ 提交于 2019-11-26 05:53:46
问题 I have seen a lot of functions being defined according to the pattern (f .) . g . For example: countWhere = (length .) . filter duplicate = (concat .) . replicate concatMap = (concat .) . map What does this mean? 回答1: The dot operator (i.e. (.) ) is the function composition operator. It is defined as follows: infixr 9 . (.) :: (b -> c) -> (a -> b) -> a -> c f . g = \x -> f (g x) As you can see it takes a function of type b -> c and another function of type a -> b and returns a function of