Last active
March 26, 2016 17:30
-
-
Save raydive/b472147ec79505750a5e to your computer and use it in GitHub Desktop.
Crystal langでPhantom Typeっぽくやりたかったけど、なんか違う
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
module A | |
class State | |
end | |
class Ready < State | |
end | |
class NotReady < State | |
end | |
end | |
class Data(T) | |
end | |
class Test | |
include A | |
def test(data : Data(Ready)) | |
print("test ok") | |
end | |
def self.start | |
t = Test.new | |
t.test(Data(Ready).new) | |
end | |
end | |
Test.start |
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
class Data(T) | |
end | |
# こういう特殊化はできないっぽい | |
class Data(NotReady) | |
def ready | |
Data(Ready).new | |
end | |
end | |
class Data(Ready) | |
def say | |
"Hello" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment