Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equality on constraints

Basically, given {-# LANGUAGE PolymorphicKinds, ConstraintKinds, TypeFamilies #-} (and more, if necessary), does the (~) type-level operator work on type-level expressions of kind Constraint? I tried googling the answer, but had no luck.

like image 548
Ptharien's Flame Avatar asked Mar 08 '12 18:03

Ptharien's Flame


People also ask

What is the difference between equality and inequality constraints?

An inequality constraint can be either active, ε-active, violated, or inactive at a design point. On the other hand, an equality constraint is either active or violated at a design point.

What is optimization with equality constraints?

Wikipedia defines optimization as a problem where you maximize or minimize a real function by systematically choosing input values from an allowed set and computing the value of the function.

What are constraints in linear inequalities?

Linear inequality constraints have the form A·x ≤ b. When A is m-by-n, there are m constraints on a variable x with n components. You supply the m-by-n matrix A and the m-component vector b. Pass linear inequality constraints in the A and b arguments.

How do you convert inequality constraints to equality constraints?

The simplest way to handle inequality constraints is to convert them to equality constraints using slack variables and then use the Lagrange theory. but at the expense of introducing r new variables. 0 = or both. (i.e. the constraint is not binding).


1 Answers

Yes, it is possible. Because types of kind Constraint are finite sets of atomic type constraints, you can test their equality very easily.

The PolyKinds extension is not necessary, however. Also, there's very few situations when this kind equality would actually be useful, because I don't see a practical way of passing polymorphic constraints as the arguments c1, c2 to Bla, so the constraint equality would be a tautology in every case (Show ~ Show here):

{-# LANGUAGE ConstraintKinds, TypeFamilies #-}

type Bla c1 c2 a = (c1 a, c2 a, c1 ~ c2)

foo :: Bla Show Show a => a -> IO ()
foo = print

main = foo "Bla"
like image 123
dflemstr Avatar answered Oct 18 '22 04:10

dflemstr