Is setting the type of the covered type possible?

Is it possible to do the following:

foo = bar where type A = (Some, Huge, Type, Sig) meh :: A -> (A, A) -> A 

I need to use this custom type inside the where clause, so it makes no sense to define it globally.

+6
source share
2 answers

It's impossible. Why not just define it over a function? You do not need to export it from the module (just use the explicit export list).

By the way, if you really have a large type, this is probably a sign that you should consider it in smaller parts, especially if you have many tuples, as your example suggests; data types will be more appropriate.

+8
source

Actually, there is one, a little ridiculous way to approach this:

 {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ScopedTypeVariables #-} foo :: forall abbrv. (abbrv ~ (Some, Huge, Type, Sig)) => abbrv -> abbrv foo x = meh x (x, x) where meh :: abbrv -> (abbrv, abbrv) -> abbrv meh xy = {- ... -} 

I cannot recommend the inclusion of two language extensions just for the sake of reducing types in signatures, although if you are already using them (or GADT instead of type families), I believe that it will do no harm.

Caring aside, you should consider how to reorganize your types in cases like ehird suggests.

+8
source

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


All Articles