Created
January 24, 2015 15:21
-
-
Save palladin/671b514df45fed287e5f to your computer and use it in GitHub Desktop.
A type-level SAT solver in F#
This file contains hidden or 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
type Bool = interface end | |
and True = True with | |
interface Bool | |
and False = False with | |
interface Bool | |
type And = And with | |
static member inline (?<-) (True, And, True) = True | |
static member inline (?<-) (True, And, False) = False | |
static member inline (?<-) (False, And, True) = False | |
static member inline (?<-) (False, And, False) = False | |
and Or = Or with | |
static member inline (?<-) (True, Or, True) = True | |
static member inline (?<-) (True, Or, False) = True | |
static member inline (?<-) (False, Or, True) = True | |
static member inline (?<-) (False, Or, False) = False | |
and Not = Not with | |
static member inline ($) (Not, True) = False | |
static member inline ($) (Not, False) = True | |
let inline (<&&>) a b = (a ? (And) <- b ) | |
let inline (<||>) a b = (a ? (Or) <- b ) | |
let inline not a = Not $ a | |
let inline solve (p : ^T -> True) = typeof< ^T>.FullName | |
solve (fun a -> not a) // False | |
solve (fun a -> not (not a)) // True | |
solve (fun (a, b) -> a <&&> (not b)) // (True, False) | |
solve (fun a -> a <&&> (not a)) // type error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment