Last active
August 29, 2015 14:19
-
-
Save morrisonlevi/fa092aa4ede926c51654 to your computer and use it in GitHub Desktop.
Abstract data types as sum types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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