Skip to main content

Combinatory Birds

Project description

cbirds


Combinator Birds

This is a port of the haskell package Data.Aviary.Birds. Please check this out if you want to see more details about the birds.

cbirds is a module intended for demonstration purposes rather than functional or practical use. The objective is to support the combinator birds in a pointfree style programming.

The only way to make sense of function combinators in python would be in a pointfree context. Lucky for us, there is a pointfree module that allows us, e.g., to compose functions smoothly and enable partial application of functions and methods.

Pointfree style has a few downsides. I'm afraid this is an unsuccessful attempt to join python pointfree and the use combinator birds. It is just a matter of time before it becomes an unreadable mess.

Examples

Let's define a function keephalf, keephalf is a function that return the first half of a list.

>>> keephalf([1,2,3,4,5,6,7,8,9,10])
[1, 2, 3, 4, 5]

I'll start by defining our own (@pointfree) version of length, integer division and and take, these functions are going to useful in the making of keephalf.

@pointfree
def pflen(l): return len(l) 
@pointfree
def div(a,x): return a // x
@pointfree
def take(n,l): return l[0:n]

Although the code below does not look like python I can guarantee you that it is! In the examples bellow the * symbol means function composition (from the pointfree module). For the ones wanting to reach the highest level of bird use, there's a combinator that composes functions: the bluebird but for reasons of readability we'll use * ,for now.

The most intuitive birds to use in the making of keephalf is the phoenix. The phoenix passes a single value through two different functions, and pass the results to a two-parameter function. We'll also use the idiot bird, that is the identity function.

#phoenix x y z w = x (y w) (z w)
#idiot x = x

keephalf = phoenix (take, cardinal (div,2) * pflen, idiot)

Let's try different birds now, let's use the starling and the cardinal . The starling passes a value straight and also through a function to another function of arity 2, and the cardinal that swaps the argument order.

#starling = x y z = x z (y z)
#cardinal x y z = x (z y)

keephalf2 = starling (cardinal (take), cardinal (div,2) * pflen)

We can also use the warbler and the cardinal__. The warbler is a elementary duplicator, the cardinal__ pass first argument straight, and second argument through a function, to a two-parameter function

#cardinal_ x y z w = x (y w) z
#warbler x y = x y y
keephalf3 = warbler (cardinal_ (take , cardinal(div, 2) * pflen))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cbirds-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

cbirds-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file cbirds-0.1.0.tar.gz.

File metadata

  • Download URL: cbirds-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for cbirds-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4f01c8a6c87fe1cc8cb1a40259c862040b6aeb8ab804ff8ba8b245e76c723962
MD5 4b08a6b36df354d960f348099636aecf
BLAKE2b-256 bb0cd9091590e29cde059974356021a88c97801aa1eca8bc5705a882032c3ccb

See more details on using hashes here.

File details

Details for the file cbirds-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cbirds-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for cbirds-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a18fe873573a2bbd9146c6ef15710de79ba39236bfd9940daeb3592ac3442a87
MD5 0cec8e574598aef7eaa6f906a7b9471f
BLAKE2b-256 099d2749d96d63120defe7ba68ced75aa04ff649c5ad2ef075f08dade7ef3cc8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page