Skip to content

Instantly share code, notes, and snippets.

@morrisonlevi
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morrisonlevi/fa092aa4ede926c51654 to your computer and use it in GitHub Desktop.
Save morrisonlevi/fa092aa4ede926c51654 to your computer and use it in GitHub Desktop.
Abstract data types as sum types
<?php
// define the classes:
class Remote {}
class UserDb {
public $hash;
function __construct($hash) {
$this->hash = $hash;
}
}
class PendingRequest {
public $hash;
function __construct($hash) {
$this->hash = $hash;
}
}
// define the sum type
type AuthenticationType = Remote | UserDb | PendingRequest;
<?php
// Enum's can be short-hand syntax for the above:
enum AuthenticationType {
Remote,
UserDb($hash),
PendingRequest($hash)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment