Is it possible to define a function on a subset of an existing type?

后端 未结 5 1768
夕颜
夕颜 2021-01-18 04:40

I\'m new to Haskell and would like to know whether it\'s possible to define a function that is only defined on a subset of an already existing type, without actually having

5条回答
  •  耶瑟儿~
    2021-01-18 05:02

    No. The type system would need to support refinement types (or full dependent types, as suggested by @jozefg).

    Here is a Haskell extension with refinement types.

    http://goto.ucsd.edu/~rjhala/liquid/haskell/blog/blog/2013/01/01/refinement-types-101.lhs/

提交回复
热议问题