Skip to content

Instantly share code, notes, and snippets.

@raydive
Last active March 26, 2016 17:30
Show Gist options
  • Save raydive/b472147ec79505750a5e to your computer and use it in GitHub Desktop.
Save raydive/b472147ec79505750a5e to your computer and use it in GitHub Desktop.
Crystal langでPhantom Typeっぽくやりたかったけど、なんか違う
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
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