[Haskell-cafe] Prevent a type parameter from sharing some of its parameters with another parameter

Timotej Tomandl tomandltimotej at gmail.com
Mon Aug 21 04:52:21 UTC 2017


As the title says.

Motivation:
in a mutable code I want to keep some parameters strictly immutable, i.e.
not sharing s with the whole mutable type

I think this is best illustrated by 2 examples:
1. abstract example:
imagine I have a type
X a b c
and another type
Y a b
and I want to prevent any case where the first parameter of X "a" is shared
with it's third parameter "c" i.e. X a b (Y a a), X a b (Y a b), X a b (Y b
a), X a b (Y a d) etc., any nestings in Y referencing a etc.
but allow
X a b (Y b b), X a b (Y b c)
and any other combination not ruled out above
2. concrete example:
imagine I have a type:
Item s element key
where s is used in the same way as in STRef s a, i.e. it cannot leak
outside of a certain context, but I want the key to be immutable i.e.
independent of s under any circumstences, so I can't write a type like:
Item s element (STRef s refType)
this is equivalent to disallowing X a b (Y a d) in 1.

Is there any way to write a restriction like this in Haskell?

--
  Timo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170821/75a0c22e/attachment.html>


More information about the Haskell-Cafe mailing list