Hacker News new | ask | show | jobs
by lpw25 4477 days ago
Also, only some things in OCaml are structurally typed (modules, objects, polymorphic vairants), others are not (records, variants). For example:

    # type meters = I of int;;
    type meters = I of int

    # let meters i = I i;;
    val meters : int -> meters = <fun>

    # type newtons = I of int;;
    type newtons = I of int

    # let newtons i = I i;;
    val newtons : int -> newtons = <fun>

    # let f b = if b then newtons 12 else meters 12;;
    Characters 36-45:
      let f b = if b then newtons 12 else meters 12;;
                                          ^^^^^^^^^
    Error: This expression has type meters but an expression was expected of type
             newtons