functional-programming

bind first argument of function without knowing its arity

て烟熏妆下的殇ゞ 提交于 2019-12-21 04:18:58
问题 I'd like to have a function BindFirst that binds the first argument of a function without me having to explicitly know/state the arity of the function by using std::placeholders. I'd like the client code to look something like that. #include <functional> #include <iostream> void print2(int a, int b) { std::cout << a << std::endl; std::cout << b << std::endl; } void print3(int a, int b, int c) { std::cout << a << std::endl; std::cout << b << std::endl; std::cout << c << std::endl; } int main()

How do I generate a random number using functional state?

和自甴很熟 提交于 2019-12-21 04:11:47
问题 I'm struggling to figure out how to merge a functional representation of State with Scala's Random class to generate random integers. I'm studying from the book Functional Programming in Scala , and so most of the code is taken from there. Here's what the State class looks like, directly from the book: case class State[S, +A](run: S => (A, S)) And here's what I want to do: object State { type Rand[A] = State[A, Random] // the Random from scala.util.Random def nextIntInRange(from: Int, to: Int

Coq: Prop versus Set in Type(n)

风流意气都作罢 提交于 2019-12-21 04:11:23
问题 I want to consider the following three (related?) Coq definitions. Inductive nat1: Prop := | z1 : nat1 | s1 : nat1 -> nat1. Inductive nat2 : Set := | z2 : nat2 | s2 : nat2 -> nat2. Inductive nat3 : Type := | z3 : nat3 | s3 : nat3 -> nat3. All three types give induction principles to prove a proposition holds. nat1_ind : forall P : Prop, P -> (nat1 -> P -> P) -> nat1 -> P nat2_ind : forall P : nat2 -> Prop, P z2 -> (forall n : nat2, P n -> P (s2 n)) -> forall n : nat2, P n nat3_ind : forall P

PHP - Displaying Urdu text retrieved from MySQL DB

那年仲夏 提交于 2019-12-21 04:09:23
问题 There are book titles in Urdu language stored in MySQL database. I've to display on html page using PHP. Currently only questions marks( ?????? ) are displayed in place of Urdu text. <div class='product_title'><a href='details.php?pid=".$Row['s_id']."'>".$Row["books"]."</a></div> What needs to be done to display these characters properly? 回答1: Step : 1 - Go to table structure and change collation latin1_swedish_ci to utf8_general_ci Step : 2 - You have to include this following tag in data

How do I “append” to an immutable dictionary in Swift?

吃可爱长大的小学妹 提交于 2019-12-21 04:03:22
问题 In Scala, the + (k -> v) operator on immutable.Map returns a new immutable.Map with the contents of the original, plus the new key/value pair. Similarly, in C#, ImmutableDictionary.add(k, v) returns a new, updated ImmutableDictionary . In Swift, however, Dictionary appears only to have the mutating updateValue(v, forKey: k) function and the mutating [k:v] operator. I thought maybe I could play some trick with flatten() , but no luck: let updated = [original, [newKey: newValue]].flatten() gets

haskell - flip fix / fix

落花浮王杯 提交于 2019-12-21 03:59:11
问题 >>>flip fix (0 :: Int) (\a b -> putStrLn "abc") Output: "abc" This is a simplified version of using flip fix . I saw this way of using it in some youtube video which are probably from google tech talk or some other talks. Can somebody give me some pointers(not some memory address, thanks!) that what exactly fix is. I know the general definition from documentation on the official site. And I have scanned through lots of stuff on the internet, just couldn't find an answer that is comprehensive

Building a class hierarchy in Coq?

回眸只為那壹抹淺笑 提交于 2019-12-21 03:56:19
问题 I can naively construct a hierarchy of algebraic structures in Coq using type classes. I'm having some trouble finding resources on Coq's syntax and semantics for type classes. However, I believe the following is a correct implementation of semigroups, monoids and commutative monoids: Class Semigroup {A : Type} (op : A -> A -> A) : Type := { op_associative : forall x y z : A, op x (op y z) = op (op x y) z }. Class Monoid `(M : Semigroup) (id : A) : Type := { id_ident_left : forall x : A, op

“int -> int -> int” What does this mean in F#?

匆匆过客 提交于 2019-12-21 03:49:13
问题 I wonder what this means in F#. “a function taking an integer, which returns a function which takes an integer and returns an integer.” But I don't understand this well. Can anyone explain this so clear ? [Update]: > let f1 x y = x+y ;; val f1 : int -> int -> int What this mean ? 回答1: F# types Let's begin from the beginning. F# uses the colon ( : ) notation to indicate types of things. Let's say you define a value of type int : let myNumber = 5 F# Interactive will understand that myNumber is

are there statically-typed functional languages?

杀马特。学长 韩版系。学妹 提交于 2019-12-21 03:37:09
问题 this is a hard thing to google, maybe SO has better answers? i'm coming from a statically-typed background and investigating functional programming, but i'm not entirely excited about dynamic typing. curious what kind of options are out there. one answer to start: ActionScript 3 is statically-typed and offers some functional paradigms, though AS3 programs don't often use them. 回答1: There are many. Haskell, OCaml and F# come to mind. If you are a Windows developer, F# is very nice and is well

Is it usual for interaction nets to leave piles of redundant fans?

a 夏天 提交于 2019-12-21 03:35:19
问题 I'm compiling lambda calculus terms to interaction nets in order to evaluate them using Lamping's abstract algorithm. In order to test my implementation, I used this church-number division function: div = (λ a b c d . (b (λ e . (e d)) (a (b (λ e f g . (e (λ h . (f h g)))) (λ e . e) (λ e f . (f (c e)))) (b (λ e f . e) (λ e . e) (λ e . e))))) Dividing 4 by 4 (that is, (λ k . (div k k)) (λ f x . (f (f (f (f x))))) ), I get this net: (Sorry for the awful rendering. λ is a lambda, R is root, D is