<div dir="ltr"><div><div><div><div>Imants,<br><br></div>You are right. The problem is not in IO here, it's that if you have access to data-constructor, you can do things like:<br><br>six :: TypeValInt 6<br>six = TypeValInt 5<br><br></div>Initially, I was making an assumption that you won't be using a data-constructor. After thinking about it a bit, I should note that my code isn't much different from just using a "smart constructor" approach, e.g. hiding a real MyP constructor, and instead providing a function:<br><br></div>mkMyP (a, b) = MyP (a, b) (b, a)<br><br></div>and exporting only this function. This would make sure all your users only create a valid set of data.<br><div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 23, 2015 at 5:05 PM, Imants Cekusins <span dir="ltr"><<a href="mailto:imantc@gmail.com" target="_blank">imantc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 23 June 2015 at 14:54, Kostiantyn Rybnikov <<a href="mailto:k-bx@k-bx.com">k-bx@k-bx.com</a>> wrote:<br>
> Hi Matt. I don't know how bad is this, but here's what I came up with.<br>
</span>...<br>
<br>
this modified for IO version accepts any input, including that which<br>
should have caused error:<br>
<br>
or did I do something wrong?<br>
<span class=""><br>
<br>
{-# LANGUAGE DataKinds #-}<br>
{-# LANGUAGE KindSignatures #-}<br>
{-# LANGUAGE ExistentialQuantification #-}<br>
{-# LANGUAGE PolyKinds #-}<br>
{-# LANGUAGE StandaloneDeriving #-}<br>
<br>
</span>module PairsMatchedKR where<br>
<br>
import GHC.TypeLits<br>
<br>
data TypeValInt (n::Nat) = TypeValInt Int<br>
<span class=""> deriving (Show)<br>
<br>
one :: TypeValInt 1<br>
one = TypeValInt 1<br>
<br>
two :: TypeValInt 2<br>
two = TypeValInt 2<br>
<br>
data MyP a b = MyP (TypeValInt a, TypeValInt b) (TypeValInt b, TypeValInt a)<br>
deriving (Show)<br>
<br>
main :: IO ()<br>
main = do<br>
putStrLn "Hello!"<br>
</span> x1 <- getLine<br>
x2 <- getLine<br>
x3 <- getLine<br>
x4 <- getLine<br>
<br>
print (MyP (tvi x1, tvi x2) (tvi x3, tvi x4))<br>
<span class=""><br>
class TypeVal (g :: a -> *)<br>
instance TypeVal TypeValInt<br>
<br>
data MyPGen a b = forall g. (TypeVal g, Show (g a), Show (g b))<br>
=> MyPGen (g a, g b) (g b, g a)<br>
deriving instance Show (MyPGen a b)<br>
<br>
<br>
</span>tvi:: String -> TypeValInt (n::Nat)<br>
tvi = TypeValInt . read<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>