Last active
October 7, 2017 20:21
-
-
Save Axure/69776381a8992570c29133fe671e2fca to your computer and use it in GitHub Desktop.
Modules in OCaml
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
trait Lazy[T[_]] { | |
type Type[X] = T[X] | |
def mk[A](thunk: () => A): T[A] | |
} | |
object LazyThunk extends Lazy[({type Thunk[X] = () => X})#Thunk] { | |
override def mk[A](thunk: () => A): () => A = thunk | |
} | |
trait StreamTrait[Thunk[_]] { | |
class StreamT[A](val tuple: Lazy[Thunk]#Type[(A, StreamT[A])]) {} | |
def hd[A](stream: StreamT[A]): A | |
} | |
class StreamClass[Thunk[_]](val lazyT: Lazy[Thunk]) extends StreamTrait[Thunk] { | |
override def hd[A](stream: StreamT[A]): A = ?? | |
} | |
// now I have to use it as | |
object App { | |
def main(args: Array[String]): Unit = { | |
val S = new StreamClass(LazyThunk) | |
// S.hd (something), etc. | |
// Can I make it static, like StreamClass[LazyThunk]? I just want to simulate modules in OCaml. | |
// Or what is the canonical way of doing this (mimcking typeclass?) in Scala, without using a module like system? | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment