How to use GADT in Hugs

I would like to write a Haskell program that uses GADT interactively on a platform not supported by GHCi (namely GNU / Linux on mipsel). The problem is that there is a construct that can be used to define GADT in the GHC, for example:

data Term a where Lit :: Int -> Term Int Pair :: Term a -> Term b -> Term (a,b) ... 

doesn't seem to work on Hugs.

  • Is it not possible to define GADT in Hugs? My TA in the Haskell class stated that this is possible in Hugs, but he does not seem to be sure.
  • If not, can GADT be encoded using different syntax or semantics supported by Hugs, just like GADT can be encoded in ocaml?
+1
source share
2 answers

GADTs are not implemented in Hugs.

Instead, you should use the GHC port for mips if you are trying to run code using GADT. Please note that you will not be able to use ghci on all platforms due to the lack of bytecode loading on more exotic architectures.

+7
source

As for your question 2 (how to code the use cases of GADT in Haskell 98), you can look at this 2006 article by Sulzman and Wang: GADTless Programming in Haskell 98 .

Like the OCaml work you are referring to, this works by factoring GADT through the equality type. There are various ways to determine the type of equality; they use the Leibniz equality form as for OCaml, which allows you to replace, through any application, a type operator in the form * -> * .

Depending on how the job of a certain type checks the correctness of the GADT equivalents, this may not be expressive enough to cover all GADT examples: the controller can apply the rules of reasoning for equality, which are not necessarily fixed by this definition. For example, a*b = c*d implies a = c and b = d : this form of decomposition does not occur if you use only type constructors in the form * -> * . Later in 2010, Oleg discussed how you can use type families to apply "type deconstructors" through Leibniz equality, obtaining decomposition properties for this definition, but of course, this is again outside of Haskell 98.

Something to keep in mind for system type designers: is your language complete for equality of labies, in the sense that it can express what a specialized equality solver can do?

Even if you find an equality type encoding that is expressive enough, you will have very practical convenience problems: when using GADT, all applications of the equality certificate are deduced from type annotations. Using this explicit encoding will do a lot more work for you.

Finally, (no pun intended), many uses of GADT can be equally expressed by tagless-final embeddings (again by Oleg), which IIRC can often do in Haskell 98. a blog post from Martin Van Steenbergen that indicates that his There are reciprocal comments in this spirit, but Oleg has significantly improved this technique.

+4
source

Source: https://habr.com/ru/post/1205511/


All Articles