combinators

How to create a lazy-seq generating, anonymous recursive function in Clojure?

岁酱吖の 提交于 2019-12-03 06:28:52
Edit : I discovered a partial answer to my own question in the process of writing this, but I think it can easily be improved upon so I will post it anyway. Maybe there's a better solution out there? I am looking for an easy way to define recursive functions in a let form without resorting to letfn . This is probably an unreasonable request, but the reason I am looking for this technique is because I have a mix of data and recursive functions that depend on each other in a way requires a lot of nested let and letfn statements. I wanted to write the recursive functions that generate lazy

How would you (re)implement iterate in Haskell?

天大地大妈咪最大 提交于 2019-12-03 03:45:52
iterate :: (a -> a) -> a -> [a] (As you probably know) iterate is a function that takes a function and starting value. Then it applies the function to the starting value, then it applies the same function to the last result, and so on. Prelude> take 5 $ iterate (^2) 2 [2,4,16,256,65536] Prelude> The result is an infinite list. (that's why I use take ). My question how would you implement your own iterate' function in Haskell, using only the basics ( (:) (++) lambdas, pattern mataching, guards, etc.) ? (Haskell beginner here) Well, iterate constructs an infinite list of values a incremented by

What are zygo/meta/histo/para/futu/dyna/whatever-morphisms?

别等时光非礼了梦想. 提交于 2019-12-03 03:09:59
问题 Is there a list of them with examples accessible to a person without extensive category theory knowledge? 回答1: Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire(PDF) should help as well. The notation will get a bit hairy, but reading it a few times you should be able to knock down that list of yours. Also, take a look at the recursion schemes (archived) blog post, the blogger plans on presenting each individually soon, so check back to it regularly --I guess. 回答2: Edward

In Haskell performing `and` and `or` for boolean functions

谁说我不能喝 提交于 2019-12-03 01:02:26
问题 I just wrote the following two functions: fand :: (a -> Bool) -> (a -> Bool) -> a -> Bool fand f1 f2 x = (f1 x) && (f2 x) f_or :: (a -> Bool) -> (a -> Bool) -> a -> Bool f_or f1 f2 x = (f1 x) || (f2 x) They might be used to combined the values of two boolean functions such as: import Text.ParserCombinators.Parsec import Data.Char nameChar = satisfy (isLetter `f_or` isDigit) After looking at these two functions, I came to the realization that they are very useful. so much so that I now suspect

Explain this implementation of the Y combinator in Scala?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 00:19:55
This is a implementation of the Y-combinator in Scala: scala> def Y[T](func: (T => T) => (T => T)): (T => T) = func(Y(func))(_:T) Y: [T](func: (T => T) => (T => T))T => T scala> def fact = Y { | f: (Int => Int) => | n: Int => | if(n <= 0) 1 | else n * f(n - 1)} fact: Int => Int scala> println(fact(5)) 120 Q1: How does the result 120 come out, step by step? Because the Y(func) is defined as func(Y(func)) , the Y should become more and more,Where is the Y gone lost and how is the 120 come out in the peform process? Q2: What is the difference between def Y[T](func: (T => T) => (T => T)): (T => T)

What are super combinators and constant applicative forms?

吃可爱长大的小学妹 提交于 2019-12-02 23:56:01
I'm struggling with what Super Combinators are: A supercombinator is either a constant, or a combinator which contains only supercombinators as subexpressions. And also with what Constant Applicative Forms are: Any super combinator which is not a lambda abstraction. This includes truly constant expressions such as 12, ((+) 1 2), [1,2,3] as well as partially applied functions such as ((+) 4). Note that this last example is equivalent under eta abstraction to \ x -> (+) 4 x which is not a CAF. This is just not making any sense to me! Isn't ((+) 4) just as "truly constant" as 12? CAFs sound like

What are zygo/meta/histo/para/futu/dyna/whatever-morphisms?

蓝咒 提交于 2019-12-02 16:39:02
Is there a list of them with examples accessible to a person without extensive category theory knowledge? Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire(PDF) should help as well. The notation will get a bit hairy, but reading it a few times you should be able to knock down that list of yours. Also, take a look at the recursion schemes (archived) blog post , the blogger plans on presenting each individually soon, so check back to it regularly --I guess. Edward Kmett recently posted a Field Guide to recursion schemes , perhaps it helps? Start with learning about

In Haskell performing `and` and `or` for boolean functions

两盒软妹~` 提交于 2019-12-02 14:22:56
I just wrote the following two functions: fand :: (a -> Bool) -> (a -> Bool) -> a -> Bool fand f1 f2 x = (f1 x) && (f2 x) f_or :: (a -> Bool) -> (a -> Bool) -> a -> Bool f_or f1 f2 x = (f1 x) || (f2 x) They might be used to combined the values of two boolean functions such as: import Text.ParserCombinators.Parsec import Data.Char nameChar = satisfy (isLetter `f_or` isDigit) After looking at these two functions, I came to the realization that they are very useful. so much so that I now suspect that they are either included in the standard library, or more likely that there is a clean way to do

What are some interesting uses of higher-order functions?

筅森魡賤 提交于 2019-12-02 14:10:31
I'm currently doing a Functional Programming course and I'm quite amused by the concept of higher-order functions and functions as first class citizens. However, I can't yet think of many practically useful, conceptually amazing, or just plain interesting higher-order functions. (Besides the typical and rather dull map , filter , etc functions). Do you know examples of such interesting functions? Maybe functions that return functions, functions that return lists of functions (?), etc. I'd appreciate examples in Haskell, which is the language I'm currently learning :) Well, you notice that

Combining two expressions into a pipeline

[亡魂溺海] 提交于 2019-12-01 21:46:08
Let us say I have the following two expressions: Expression<Func<T, IEnumerable<TNested>>> collectionSelector; Expression<Func<IEnumerable<TNested>, TNested>> elementSelector; Is there a way to "combine" these in order to form the below: (?) Expression<Func<T, TNested>> selector; EDIT: Performance is very critical, so I would appreciate an optimal solution with very little overhead, if possible. Many Thanks! static Expression<Func<A, C>> Foo<A, B, C>( Expression<Func<B, C>> f, Expression<Func<A, B>> g) { var x = Expression.Parameter(typeof(A)); return Expression.Lambda<Func<A, C>>( Expression