Hi, Reddit Teachers! Below is a new video in our free series on grammar. It offers a functional definition of the predicate, explains its catch-all function, leads viewers through variations in its form, and highlights the important role of the essential predicating verb. youtube.com/watch?v=MniZq…
πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/OSU-SWLF
πŸ“…︎ Jun 07 2021
🚨︎ report
Hi, Reddit ELA Teachers! Here's our new lesson for our free, OER series on grammar. The video explains the subject-predicate relationship, offers several useful methods for identifying the subject, introduces a functional definition for the subject, and provides numerous examples of robots dancing. youtube.com/watch?v=Kp65w…
πŸ‘︎ 10
πŸ’¬︎
πŸ‘€︎ u/OSU-SWLF
πŸ“…︎ Jun 01 2021
🚨︎ report
A predicate transformer semantics for effects (Functional Pearl) youtu.be/iU7UtoM7WeE
πŸ‘︎ 41
πŸ’¬︎
πŸ‘€︎ u/ysangkok
πŸ“…︎ Dec 15 2019
🚨︎ report
MC-178111: The predicate condition damage_source_properties is not functional

This bug wasn't reported by myself but I think it could use attention and discussion.

This has been around for a while and is quite a frustrating issue. If it were fixed, it would open up so many possibilites for mapmakers and datapack developers.

I've seen a lot of people saying it should be WAI due to how predicates are set up in the source code, but it's still called from the predicate file and the condition isn't flagged as invalid by the output log, so it seems more like an oversight by the devs than something that was intended.

Thoughts?
Edit: link

πŸ‘︎ 6
πŸ’¬︎
πŸ‘€︎ u/U2106_Later
πŸ“…︎ May 30 2020
🚨︎ report
Cettia Java Server 1.2.0 released with functional programming support; socket predicates and socket actions cettia.io/blog/cettia-jav…
πŸ‘︎ 11
πŸ’¬︎
πŸ‘€︎ u/flowersinthesand
πŸ“…︎ Nov 05 2018
🚨︎ report
Functional Programming Unit Testing in Node - Part 2: Predicates, Async, and Unsafe javascript.works-hub.com/…
πŸ‘︎ 18
πŸ’¬︎
πŸ“…︎ Jun 26 2018
🚨︎ report
Ranges, summation and predicates - Functional programming in JavaScript

I'm currently reading about how functional programming concepts can be applied to JavaScript. I wrote up this post showing how to solve a fairly simple challenge using these initially alien concepts. I'd love to see this kind of thing use more widely throughout the JavaScript community.

πŸ‘︎ 21
πŸ’¬︎
πŸ‘€︎ u/Wolfy87
πŸ“…︎ Jul 02 2013
🚨︎ report
Need to create a function that works only on types matching certain predicate? Fear no more!
#[allow(incomplete_features)]
#![feature(generic_const_exprs)]

fn something<T>(val: T)
where
    Assert<{ core::mem::size_of::<T>() < 768 }>: IsTrue,
    //       ^-----------------------------^ any const-expression will do
{
    //
}

fn main() {
    something([0u8; 0]); // ok
    something([0u8; 512]); // ok
    something([0u8; 1024]); // compilation error, yass
}

// ---

pub enum Assert<const CHECK: bool> {
    //
}

pub trait IsTrue {
    //
}

impl IsTrue for Assert<true> {
    //
}

Example use cases include trying to write an async executor for a platform that has tight RAM limits πŸ˜…

πŸ‘︎ 146
πŸ’¬︎
πŸ‘€︎ u/Patryk27
πŸ“…︎ Jan 12 2022
🚨︎ report
How to declare an exportable type for a complex type predicate defined inside a function?

I am using type predicates to build a validation function that depends on two generic types, the second of which is declared inside the first. How do I define an exportable type for the validation function that users of my library can use? Here is a simple test case:

type Nice = <D>(d: D) => d is D

function s0<S>(s: S) {
  function s1() { }
  function s2<D>(d: D): d is (D & S) {
    Object.assign(d, s)
    return true
  }
  s1.s2 = s2
  return s1
}


let i1 = s0({ a: 1 })
// I want:
// let i1: Nice = s0({ a: 1 })
// BUT d1.a will then fail

let d1 = { b: 2 }
if (i1.s2(d1)) {
  console.log(d1) // prints { a: 1, b: 2} 
  console.log(d1.a) // from S
  console.log(d1.b) // from D
  // console.log(d1.c) // fails as intended
}

What should the type declaration for Nice be? How do I get "hold" of the S generic outside of function s0?

πŸ‘︎ 16
πŸ’¬︎
πŸ‘€︎ u/rjrodger
πŸ“…︎ Jan 12 2022
🚨︎ report
In C#, whenever I want to pass a function into another function, I have to remind myself of the syntax for the generic delegate types (Action, Func, Predicate). In case anyone else has a similar issue, I made a video that goes over all of them. I hope it's helpful! youtu.be/E-g8Ivss0Gs
πŸ‘︎ 18
πŸ’¬︎
πŸ‘€︎ u/markv12
πŸ“…︎ Dec 12 2021
🚨︎ report
Trying to translate JS function to predicate

hello I'm looking for a human to tell me at least one difference to this prolog code:

dontknowhowtocallthis(N,N,I,C,C):-
    0 =\= N mod I, !.

dontknowhowtocallthis(N,Na,I,Ca,C):-
    0 is N mod I,
    N1 is N / I,
    C1 is Ca+1,
    dontknowhowtocallthis(N1,Na,I,C1,C).

dontknowhowtocallthiseither(N,I,R,R):-
    I>N, !.

dontknowhowtocallthiseither(N,I,Ra,R):-
    I=<N,
    I1 is I+1,
    (0 is N mod I->
        dontknowhowtocallthis(N,N1,I,0,C),
        R1 is Ra*((C-1)*3)+4,
        dontknowhowtocallthiseither(N1,I1,R1,R)
    ;
        dontknowhowtocallthiseither(N,I1,Ra,R)
    ).

dontknowhowtocallthiseither(N,R):- 
    dontknowhowtocallthiseither(N,2,1,R).

c(K, R):-
    N is sqrt(K),
    N2 is floor(N),
    (N =\= N2->
        R=0
    ;
        dontknowhowtocallthiseither(N2,R)
    ).

that will make it behave like the following c(k) js function:

function c(k) {
  let n = Math.sqrt(k), res = 1;
  if (Math.floor(n) !== n) return 0; 
  for (let i = 2; i <= n; i++) {
    if (n % i !== 0) continue;
    let count = 0;
    while (n % i === 0) {
        n = n / i;
        count++;
    }
    res *= ((count-1) * 3) + 4;
  }            
  return res;
}

Needless to say, I consider myself a prolog newbie and I often get stuck when trying to translate something from an imperative language into prolog.

Something that takes me a couple hours to get a hold on when learning a new imperative language (such as translating that piece of js code) is honestly consuming years for me to adjust to in prolog. I've been practicing for years, and I can't translate that piece of sh*t function with two loops. It's really discouraging. Every time I have to ask a question such as this one on reddit I just feel like I'm never going to get it. This is not for homework or anything of the sort, I just want to learn to use prolog because I think it's such a neat language. But it too often feels like futile effort, only for someone on the internet post a simple, absolutely easy-to-verify solution I may never be able to produce myself in the context of this language.

The fact that it's comparatively a small community makes things even harder because there's barely no place to just read some damn code to try and get it.

Naming stuff is also a huge internal battle because p

... keep reading on reddit ➑

πŸ‘︎ 6
πŸ’¬︎
πŸ‘€︎ u/_Nexor
πŸ“…︎ Oct 11 2021
🚨︎ report
How to get acces to the previous element in a container for a predicate function?

Let's say I have a list of pair(Int,Int) v, and I want to first apply a map to it then take out all the elements that have a 1 before them.

v.map{it.first == it.second}.filterIndexed { index, b ->
            ///And here I have a problem
        }

I can't do v[index - 1], since we don't care about v[index - 1], we care about the mapped version. We could do a map first and then do this in another variable but we shouldn't have to compromise on composability to solve a problem this simple. What's an elegant solution?

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/Acidic_Jew2
πŸ“…︎ Sep 30 2021
🚨︎ report
Type Predicates and Assertion Functions

Hi all,

I published a package including a collection of type predicates and assertion functions. It took a while to code and document because its quite comprehensive. I'd love some stars and especially some input. Here is the link:

https://github.com/tool-belt/type-predicates

πŸ‘︎ 29
πŸ’¬︎
πŸ‘€︎ u/Goldziher
πŸ“…︎ Aug 09 2021
🚨︎ report
πŸ›« Level up your collections skills! In this episode of Standard Library Safari by @sebi_io , you’ll learn about advanced collection functionality: βœ… Checking predicates πŸ“Š Chunks & Windows πŸ₯ž Flattening πŸ§ͺ Reducing & Folding ...and more! Check it out! youtu.be/N4CpLxGJlq0
πŸ‘︎ 24
πŸ’¬︎
πŸ‘€︎ u/Anisim_1
πŸ“…︎ Jun 12 2021
🚨︎ report
Predicate function for Org Agenda Items

I am trying to make a custom link-hint type for org agenda items (e.g., each line that is not a block header in org agenda). To do so I need a predicate function that returns non-nil if the thing at point is an item that could be acted on by `org-agenda-goto`.

I am having troubling finding such a function but I imagine it must exist. Help would be much appreciated!

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/JustinSilverman
πŸ“…︎ Aug 31 2021
🚨︎ report
Type Predicate and Assertion Functions github.com/tool-belt/type…
πŸ‘︎ 9
πŸ’¬︎
πŸ‘€︎ u/Goldziher
πŸ“…︎ Aug 09 2021
🚨︎ report
In C#, whenever I want to pass a function into another function, I have to remind myself of the syntax for the generic delegate types (Action, Func, Predicate). In case anyone else has a similar issue, I made a video that goes over all of them. I hope it's helpful! youtu.be/E-g8Ivss0Gs
πŸ‘︎ 44
πŸ’¬︎
πŸ‘€︎ u/markv12
πŸ“…︎ Mar 07 2021
🚨︎ report
In C#, whenever I want to pass a function into another function, I have to remind myself of the syntax for the generic delegate types (Action, Func, Predicate). In case anyone else has a similar issue, I made a video that goes over all of them. I hope it's helpful! youtu.be/E-g8Ivss0Gs
πŸ‘︎ 22
πŸ’¬︎
πŸ‘€︎ u/markv12
πŸ“…︎ Mar 07 2021
🚨︎ report
In C#, whenever I want to pass a function into another function, I have to remind myself of the syntax for the generic delegate types (Action, Func, Predicate). In case anyone else has a similar issue, I made a video that goes over all of them. I hope it's helpful! youtu.be/E-g8Ivss0Gs
πŸ‘︎ 34
πŸ’¬︎
πŸ‘€︎ u/markv12
πŸ“…︎ Mar 07 2021
🚨︎ report
If I have a list of predicate functions how can I grab them out of the list and use them?

For example if I have

(define lofuncs (list boolean?, func2 ...))

and I want to grab the boolean? predicate and use it.

(first lofuncs  2) ;; 2 is not a boolean, so returns False.

The above won't work because "first" doesn't know what to do with the 2nd argument.

Is there another way to do this?

πŸ‘︎ 7
πŸ’¬︎
πŸ‘€︎ u/EarlyYogurt
πŸ“…︎ Nov 30 2020
🚨︎ report
In C#, whenever I want to pass a function into another function, I have to remind myself of the syntax for the generic delegate types (Action, Func, Predicate). In case anyone else has a similar issue, I made a video that goes over all of them. I hope it's helpful! youtu.be/E-g8Ivss0Gs
πŸ‘︎ 7
πŸ’¬︎
πŸ‘€︎ u/markv12
πŸ“…︎ Mar 07 2021
🚨︎ report
How to create a function to check if a function is a predicate in Racket?

It would be nice if there is function that takes a function as an argument and should return #t when the given function is a predicate, #f otherwise. For example:

the structure would be: (predicate? fn)

(predicate? even?) => #t

(predicate? add1) => #f

(predicate? prime?) => #t

(predicate? expt) => #f

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/amuthyan
πŸ“…︎ Dec 20 2020
🚨︎ report
Racket Predicate Functions Package

The package contains various predicate functions that can be imported in your project.

  • To install, run raco pkg install racket-predicates
  • Then to use in a module, (require racket-predicates)

Import in DrRacket IDE: - Clone the project in the local using `git clone <repo name>` - DrRacket -> File -> Install Package - Under Package Source paste: https://github.com/aryaghan-mutum/racket-predicates - Click Install or Update - Open a file and import the package: (require racket-predicates)

πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/amuthyan
πŸ“…︎ Dec 12 2020
🚨︎ report
What is the implementation of the list? predicate function?

Hi, I am trying to implement a function by the name list? to check if it's argument is a list or not. Essentially it supposed to return either true or false, since it is a predicate procedure. Any ideas?

For ex:

#lang racket
(require rackunit)

(check-true (list? '()))
(check-true (list? '(a b)))
(check-false (list? '(a . b)))
(check-false (list? #f))
(check-false (list? 2))
(check-false (list? 'lisp))
(check-false (list? "lisp"))
πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/amuthyan
πŸ“…︎ Dec 25 2020
🚨︎ report
Using a predicate function in display-buffer-alist

Hi everyone, I'm looking for some help concerning display-buffer-alist.
I want to add a rule for .pdf files that are created with LaTeX. My first thought was to use a predicate function that, given a .pdf, checks if there exists a corresponding .tex in the same folder.

According to the documentation of display-buffer-alist, it should be possible to specify a predicate function taking two arguments instead of a regexp, so I wrote a small function and added it to display-buffer-alist:

(defun cst/latex-pdf-p (buffer-name action)
  "Determine if there is a corresponding .tex file in the current folder."
  (when (string= "pdf" (file-name-extension buffer-name))
    (file-exists-p (concat (file-name-base buffer-name) ".tex"))))

(setq display-buffer-alist
      `((#'cst/latex-pdf-p . ((display-buffer-reuse-window display-buffer-in-side-window)
                              (side . right)
                              (slot . 1)
                              (window-width . 0.33)
                              (reusable-frames . nil)))))

It doesn't work however, the rule does not get applied to any .pdf file. The predicate function alone works when called from a buffer visiting a .pdf file.

I feel like I misunderstand how the function should be specified, also I don't see why it has to get to arguments instead of just one (the name of the buffer).

Can anyone help me out here? Thanks in advance!

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/ergo93
πŸ“…︎ Nov 26 2020
🚨︎ report
Using member function as predicate in call to std::any_of

I'm trying to use a member function as a predicate in a call to std::any_of, but somehow I can't get the syntax right. I have the following vector:

std::vector&lt;std::unique_ptr&lt;Foo&gt;&gt; foos;

and a member function

Foo::canHandle(const std::string&amp; command);

then I call

std::any_of(foos.cbegin(), foos.cend(), [this](const std::string&amp; cmd) { return canHandle(cmd); })

which gives me an error like

error C2664: 'bool Foo::someFunction::&lt;lambda\_367e86da87c92c47ac2e3bfff06b1b6b&gt;::operator ()(const std::string &amp;) const': cannot convert argument 1 from 'const std::unique\_ptr&lt;Foo,std::default\_delete&lt;Foo&gt;&gt;' to 'const std::string &amp;'

I'm sure I'm messing things up quite a bit here, but can't seem to get the syntax right... any help appreciated :-)

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/Bart_VDW
πŸ“…︎ Sep 07 2020
🚨︎ report
What is meant by β€œpredicate functions” in lisp/scheme?

Why are they called predicate functions? They just seem like regular functions to be called in my opinion.

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/tempanon5
πŸ“…︎ Sep 13 2020
🚨︎ report
alex-gutev/generic-cl Β· v0.5 Β· generic function wrapper over various functions in the Common Lisp standard, such as equality predicates and sequence operations. github.com/alex-gutev/gen…
πŸ‘︎ 17
πŸ’¬︎
πŸ‘€︎ u/dzecniv
πŸ“…︎ Nov 17 2019
🚨︎ report
Difference between predicate and function?

Hi so I'm a bit confused as to the difference between predicates and functions. I understand they have different functors, but what exactly makes them different? Is it just the use of an operator? Or the ability to prove true/false or smth?

Thanks!

πŸ‘︎ 11
πŸ’¬︎
πŸ‘€︎ u/iloos
πŸ“…︎ Feb 15 2020
🚨︎ report
Datomic tuples and database predicates - declare Clojure functions for constraining your database blog.datomic.com/2019/06/…
πŸ‘︎ 29
πŸ’¬︎
πŸ‘€︎ u/stuarthalloway
πŸ“…︎ Jun 28 2019
🚨︎ report
Grammar Points of the function word 很 (hΔ›n) :As an adverb, 很, meaning "very, quite, pretty", can be used to emphasize the degree. In some contexts, 很 is only used for grammatical purpose, to link subject and predicate adjective. youtube.com/watch?v=KXutc…
πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/Daily_Zhongwen
πŸ“…︎ Dec 22 2019
🚨︎ report
A new design pattern for implementing capturing closures in C

Recently, I've came up with a new method of implementing closures in C. The idiomatic way is passing a closure as a pair of a function pointer and a void* value as the context. However, this idiom is a bit cumbersome. Firstly, two entities have to maintained instead of one. The other problem is which parameter should the context be bound to. It can be really confusing when the function takes multiple void* as parameters.

The main obstacle for having nice closures C is binding data to a function pointer. It cannot be done robustly without creating function on fly with a library or compiler extension like "nested functions" in GCC. However, there is a creature that combines a function and data. And this creature is a pointer to a function pointer. The function pointer is data though it points to non-data. It can be used to implement a wide function pointer.

Take a look on the following C89 compliant code:

#include &lt;stdio.h&gt;

typedef int filter_fn(void*, int);

/* prints number from range 1 to `n` that satisfy condition from `filter` */
void print_filtered(int n, filter_fn **filter) {
    int i;
    for (i = 1; i &lt;= n; ++i)
        if ((*filter)(filter, i))
            printf("%d ", i);
    puts("");
}

struct is_divisible {
    int (*closure)(void*,int);
    int divisor;
};

int is_divisible(void* closure, int n) {
    struct is_divisible *ctx = closure;
    return (n % ctx-&gt;divisor) == 0;
}

int is_prime(void *closure, int n) {
    int d;
    (void)closure;
    if (n &lt;= 1) return 0;
    for (d = 2; d * d &lt;= n; ++d)
        if (n % d == 0)
            return 0;
    return 1;
}

int main() {
    struct is_divisible is_divisible_by_3 = { is_divisible, 3 };
    static int (*is_prime_closure)(void*,int) = is_prime;

    puts("Divisible by 3");
    print_filtered(20, &amp;is_divisible_by_3.closure);

    puts("Primes");
    print_filtered(20, &amp;is_prime_closure);

    return 0;
}

It prints the expected output:

Divisible by 3
3 6 9 12 15 18 
Primes
2 3 5 7 11 13 17 19 

The trick is to place a function pointer as a first member of the struct representing the captured context. This first member can be safely cast to the context. It is is guaranteed to work by the C standard, see https://port70.net/~nsz/c/c11/n1570.html#6.7.2.1p15

&gt

... keep reading on reddit ➑

πŸ‘︎ 66
πŸ’¬︎
πŸ‘€︎ u/tstanisl
πŸ“…︎ Jan 21 2022
🚨︎ report
How important are label for sum types?

For my language, Flogram, I've been designing sum types so they can either be a object type or a label, basically an enum. Can have as many labels as possible.

Example:

new tree_node : node | _no_node = _no_node

The above line creates a new variable called tree_node, node is an object, _no_node is a enum and I'm assigning an initial value of _no_node.

But I'm looking at Rust and Haskell and noticing they allow both labels as object type to be mixed. I don't see places where it would be all that useful, it's easy to work around but adding a type to the object that can only be enums if needed, and it's one more concept to add to the language which I'm trying to avoid unless needed, but maybe it is more useful more often than I realize.

Something like this:

new my_car : Subaru>Car | Ford>Car | >Car | No_Car

Where my is an object that either have a label 'Subaru' and be a Car object, or have a 'label' Ford and have a Car Object, or be a Car without a label, or have a label 'No_Car' without

If something doesn't have both a label and object type then if it has > infront of it, it's an Object type, if it doesn't have '>' in front, then it's a label.

This also becomes more complicated when it comes to matching, because without types:
if(tree_node is node){

}

But is I have labels, is doesn't really make sense for labels, like this, has to be:

if(my_car is car){

}

if(my_car labeled Ford){

}

Would love to hear your thoughts. Thanks in advance, love this community!

πŸ‘︎ 30
πŸ’¬︎
πŸ‘€︎ u/mczarnek
πŸ“…︎ Jan 15 2022
🚨︎ report
It's the holiday season, and you know what THAT means.

...but in case you don't:

that pronoun (1) \ ˈt͟hat , t͟hΙ™t
plural those\ ˈt͟hōz
Definition of that

(Entry 1 of 5) 1a : the person, thing, or idea indicated, mentioned, or understood from the situation that is my father b : the time, action, or event specified after that I went to bed c : the kind or thing specified as follows the purest water is that produced by distillation d : one or a group of the indicated kind that's a catβ€”quick and agile 2a : the one farther away or less immediately under observation or discussion those are maples and these are elms b : the former one 3a β€”used as a function word after and to indicate emphatic repetition of the idea expressed by a previous word or phrase he was helpful, and that to an unusual degree b β€”used as a function word immediately before or after a word group consisting of a verbal auxiliary or a form of the verb be preceded by there or a personal pronoun subject to indicate emphatic repetition of the idea expressed by a previous verb or predicate noun or predicate adjective is she capable? She is that

4a : the one : the thing : the kind : something, anything the truth of that which is true the senses are that whereby we experience the world what's that you say b those plural : some persons those who think the time has come

πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/TheSolarJetMan
πŸ“…︎ Dec 24 2021
🚨︎ report
First Fully Functional Decentralized Predication Market Starts Running_Cointime cointime.com/blockchain/1…
πŸ‘︎ 8
πŸ’¬︎
πŸ‘€︎ u/SaiZhang
πŸ“…︎ Apr 27 2018
🚨︎ report
Libraries of static predicates and functions?

Hi Java people of Reddit:

Does anyone know of any existing libraries with standard useful utility predicates and functions? I'm thinking of utilities like not null / not empty, e.g. being able to write things like:

someListOfStrings.stream().filter(HelpfulPredicatesLibrary::notNullNotEmpty).collect(Collectors.toList());

Thanks!

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/SeattlePart2
πŸ“…︎ Mar 05 2018
🚨︎ report
Is "monad tutorial" problem solved?

It seems like with the rise of monadic pattern in other languages, tutorials regarding functor & monad seemed to have improved by a lot. It looks to me that the infamous monad tutorial problem is solved - ppl can learn what is monad / functor without much difficulty compared to learning other patterns. I also tried explaining functor & monad to my mother, who's over 60s now. She have never done programming past COBOL era (lol). However, she said that the concept itself seems quite trivial. (Concurrency was harder to explain) If so, the learning problem with haskell is less with functor/monads, right? To me, the culprit seems to be the error messages. (E.g. Having to learn monad to comprehend IO-related type errors)

  • Btw, why is higher kinded polymorphism hard? It just seems to me as generalization of simpler generics.
πŸ‘︎ 9
πŸ’¬︎
πŸ‘€︎ u/someacnt
πŸ“…︎ Jan 13 2022
🚨︎ report
Nested quantifiers and a predicate function

P(x,y) is the predicate function: (Domain: all rational numbers).

x+2y=xy

I am curious whether or not the following two propositions are true or false.

  1. βˆ€xβˆƒy P(x,y)

  2. βˆƒxβˆ€y P(x,y)

I guess 1) is false. Since this kind of stuff works exactly like a nested for loop right? basically I pick an y for instance y=0, and then I see if the statement P(x,0) is true for all x. it is clearly not for x=1 or x=2, next. I see if it is true for y=1, ie if p(x,1) is true for all x, it is not for instance it isn't for x=0, etc and like that I can continue and since I can never find a y where p(x,y) holds for all x this statement is false.

Is my reasoning correct here?

Now what about the second one here.

I pick an y for instance y=0, does it then exist an x? where p(x,0) is true? yes. but what about y=1? is p(x,0) for 1 x ? I am getting no here. since βˆƒx (x+2=x(1)) doesn't really make much sense since I get 0=2. (no matter what I pick x). Is the way I am going about this correct?

Also, another question:

is p β†’ (Β¬q β†’ q) ≑ q

a tautology?

I suppose this is just about checking the truth table for

p β†’ (Β¬q β†’ q) ↔ q

right? or am I misunderstanding?

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/statrowaway
πŸ“…︎ Apr 07 2018
🚨︎ report
pcostanza/filtered-functions: an extension of CLOS generic function invocation that enables the use of arbitrary predicates for selecting and applying methods. github.com/pcostanza/filt…
πŸ‘︎ 12
πŸ’¬︎
πŸ‘€︎ u/dzecniv
πŸ“…︎ Sep 03 2018
🚨︎ report
How to test your idea (predicates, key-functions) rather than the prelude function?

Hi /r/haskell,

I absolutely love the idea of property-based testing, but I have a hard time coming up with good tests. A lot of the work I do is stringing maps, filters and sorts together. The thing is that I feel that I am not testing my ideas behind the composing of the functions, but rather the prelude functions themselves.

To give an example to guide the discussion, I had to write a program that given a blacklist of ids and a list of sets of ids has to remove the sets that contain one or more of the ids in the blacklist. (The original is written in python, but is reproduced here in Haskell. It's essentially the same).

import qualified Data.Set as Set

blacklist = Set.fromList [2,3]
idset = [Set.fromList[2,5,6], Set.fromList[5,4,6]]

blacklist_filtering = filter (Set.null . Set.intersection blacklist) 

main = print $ blacklist_filtering idset
{-- result := fromList[5,4,6] --}

So how would one test this? We could test that when we apply the blacklist filter again on the already filtered list that we should get the same result. However, does this really test my logic or is this more a test for filter? I think this is more a test for filter. One could argue that in a language like python which has side-effects/states that this is still useful. However I know that my function behaves as a function without side effects.

What would be a good test for blacklist_filtering, both in a functional language and in a non-functional language like python (which has property based testing support via the hypothesis package)? Or is this something you normally wouldn't test?

Furthermore, this question isn't limited to filter. You could do the same for sort, takewhile, etcetera, almost everything that takes a predicate or a key function. To expand, sort also acts idempotent, but you aren't really testing your 'key function' on which you would want to sort if you sort the same list again. (Assuming your using the prelude sort and not a custom one).

πŸ‘︎ 9
πŸ’¬︎
πŸ‘€︎ u/exarge
πŸ“…︎ Sep 25 2015
🚨︎ report
Predicate Higher Order Functions

Lots of functions in haskell seem to deal with functions of the type

a -&gt; Bool

and there have been several times recently when I have wanted to apply logical operators to two such functions. Something like

pand :: (a -&gt; Bool) -&gt; (a -&gt; Bool) -&gt; a -&gt; Bool
pand f g x = f x &amp;&amp; g x

and the equivalent functions for other logical operators like or, xor, nand, nor. It seems like Data.Function.Predicate is the perfect place to toss these functions, but it feels like a pretty barren place to me.

I feel like I must be missing a really obvious way to transform (&&) into the above function. Is there a slick way to accomplish what I'm after without just defining the functions myself?

πŸ‘︎ 8
πŸ’¬︎
πŸ‘€︎ u/R3v3nan7
πŸ“…︎ Dec 27 2015
🚨︎ report
What is meant by β€œpredicate functions” in lisp/scheme?

Why are they called predicate functions? They just seem like regular functions to be called in my opinion.

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/tempanon5
πŸ“…︎ Sep 13 2020
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.