Comments on: What Constraints Entail: Part 2 http://comonad.com/reader/2011/what-constraints-entail-part-2/ types, (co)monads, substructural logic Sat, 29 Dec 2012 15:18:06 -0800 http://wordpress.org/?v=2.8.4 hourly 1 By: zzo38 http://comonad.com/reader/2011/what-constraints-entail-part-2/comment-page-1/#comment-105341 zzo38 Tue, 26 Jun 2012 19:08:42 +0000 http://comonad.com/reader/?p=461#comment-105341 I like this! Nevertheless they are not perfect, not like real superclass, it is why I wanted to define my own programming language to correct these things, but at least Haskell has been improved by these thing so that much works OK. I like this! Nevertheless they are not perfect, not like real superclass, it is why I wanted to define my own programming language to correct these things, but at least Haskell has been improved by these thing so that much works OK.

]]>
By: Philip J-F http://comonad.com/reader/2011/what-constraints-entail-part-2/comment-page-1/#comment-103013 Philip J-F Thu, 01 Mar 2012 07:04:59 +0000 http://comonad.com/reader/?p=461#comment-103013 Inspired by this discussion I wrote a post showing how to get multiple, passable, effectively first-class, instances. I borrowed your applicative example: http://joyoftypes.blogspot.com/2012/02/haskell-supports-first-class-instances.html Inspired by this discussion I wrote a post showing how to get multiple, passable, effectively first-class, instances. I borrowed your applicative example: http://joyoftypes.blogspot.com/2012/02/haskell-supports-first-class-instances.html

]]>
By: Edward Kmett http://comonad.com/reader/2011/what-constraints-entail-part-2/comment-page-1/#comment-85122 Edward Kmett Thu, 17 Nov 2011 19:57:21 +0000 http://comonad.com/reader/?p=461#comment-85122 I raised the issue to Max. Not sure there is a good way for it to be defined in user land, because () => q and q are interchangeable, so it would require compiler support. The most compelling use case is to make code like on :: (p a, p b) => (c -> c -> d) -> (forall x. p x => x -> c) -> a -> b -> d inhabitable for ((++) `on` show) but it impacts all sorts of unrelated areas in the compiler. I raised the issue to Max. Not sure there is a good way for it to be defined in user land, because

() => q and q are interchangeable, so it would require compiler support.

The most compelling use case is to make code like

on :: (p a, p b) => (c -> c -> d) -> (forall x. p x => x -> c) -> a -> b -> d

inhabitable for

((++) `on` show)

but it impacts all sorts of unrelated areas in the compiler.

]]>
By: Doug McClean http://comonad.com/reader/2011/what-constraints-entail-part-2/comment-page-1/#comment-85119 Doug McClean Thu, 17 Nov 2011 19:43:53 +0000 http://comonad.com/reader/?p=461#comment-85119 Yeah, I was thinking of that definition and the corresponding type family Unqualified t :: * type instance Unqualified (p => q) = q Alas there is a logical reason why it doesn't make sense. {-# LANGUAGE CommunistTypeSynonyms #-}? Yeah, I was thinking of that definition and the corresponding

type family Unqualified t :: *
type instance Unqualified (p => q) = q

Alas there is a logical reason why it doesn’t make sense.

{-# LANGUAGE CommunistTypeSynonyms #-}?

]]>
By: Edward Kmett http://comonad.com/reader/2011/what-constraints-entail-part-2/comment-page-1/#comment-85115 Edward Kmett Thu, 17 Nov 2011 19:13:11 +0000 http://comonad.com/reader/?p=461#comment-85115 As an aside, you can _write_ type family Constraints t :: Constraints type instance Constraints (p => q) = p you just can't use it anywhere. =/ The compiler complains when you go to use it that you need LiberalTypeSynonyms even if you have LiberalTypeSynonyms turned on. ;) As an aside, you can _write_

type family Constraints t :: Constraints
type instance Constraints (p => q) = p

you just can’t use it anywhere. =/

The compiler complains when you go to use it that you need LiberalTypeSynonyms even if you have LiberalTypeSynonyms turned on. ;)

]]>
By: Doug McClean http://comonad.com/reader/2011/what-constraints-entail-part-2/comment-page-1/#comment-85094 Doug McClean Thu, 17 Nov 2011 16:39:00 +0000 http://comonad.com/reader/?p=461#comment-85094 Ah, ok, I'm on the right page now. This can't work because context reduction/constraint simplification is such a mess. Probably a good thing, too, because for something like this you wouldn't want any context reduction in the first place, you'd want the naively inferred context that is based solely on what class functions are actually mentioned in a definition. This is because you might want to occasionally use an ordering on, say, lists other than the lexical one in the prelude (say, by sum or whatever). If the context gets reduced from Ord ([Salary]) to Ord Salary then you've already lost your chance. Proxies it is. Ah, ok, I’m on the right page now. This can’t work because context reduction/constraint simplification is such a mess.

Probably a good thing, too, because for something like this you wouldn’t want any context reduction in the first place, you’d want the naively inferred context that is based solely on what class functions are actually mentioned in a definition.

This is because you might want to occasionally use an ordering on, say, lists other than the lexical one in the prelude (say, by sum or whatever). If the context gets reduced from Ord ([Salary]) to Ord Salary then you’ve already lost your chance.

Proxies it is.

]]>
By: Edward Kmett http://comonad.com/reader/2011/what-constraints-entail-part-2/comment-page-1/#comment-84953 Edward Kmett Thu, 17 Nov 2011 00:23:20 +0000 http://comonad.com/reader/?p=461#comment-84953 Dan Peebles has some nice examples for things like a more polymorphic 'on' that could benefit, but in the meantime, one can use explicit proxies to work around the inability to name the constraint implicitly. Dan Peebles has some nice examples for things like a more polymorphic ‘on’ that could benefit, but in the meantime, one can use explicit proxies to work around the inability to name the constraint implicitly.

]]>
By: Edward Kmett http://comonad.com/reader/2011/what-constraints-entail-part-2/comment-page-1/#comment-84952 Edward Kmett Thu, 17 Nov 2011 00:20:46 +0000 http://comonad.com/reader/?p=461#comment-84952 discharge :: (c => t) -> Dict c -> t discharge t Dict = t works fine. as for whether the type checker has the machinery, that is somewhat harder to answer, becuase it would depend on the details of the largely underspecified constraint simplifier. discharge :: (c => t) -> Dict c -> t
discharge t Dict = t

works fine.

as for whether the type checker has the machinery, that is somewhat harder to answer, becuase it would depend on the details of the largely underspecified constraint simplifier.

]]>
By: Doug McClean http://comonad.com/reader/2011/what-constraints-entail-part-2/comment-page-1/#comment-84938 Doug McClean Wed, 16 Nov 2011 22:51:10 +0000 http://comonad.com/reader/?p=461#comment-84938 That explains why you can't define them in Haskell, but I don't think it bars you from adding them as primitives, does it? And the type checker already has the implementation that would back the primitive? I don't have access to a machine with bleeding edge GHC on it at the moment, but is (c => t) -> Dict c -> t a syntactically valid type? If not, why not? That explains why you can’t define them in Haskell, but I don’t think it bars you from adding them as primitives, does it? And the type checker already has the implementation that would back the primitive?

I don’t have access to a machine with bleeding edge GHC on it at the moment, but is (c => t) -> Dict c -> t a syntactically valid type? If not, why not?

]]>
By: Edward Kmett http://comonad.com/reader/2011/what-constraints-entail-part-2/comment-page-1/#comment-84931 Edward Kmett Wed, 16 Nov 2011 22:28:07 +0000 http://comonad.com/reader/?p=461#comment-84931 The problem with Qualifier and Unqualified is that unification of types involving => isn't done by simple unification, but instead by bi-implication for constraints, so while you can write some types with them, you typically can't build inhabitants. The problem with Qualifier and Unqualified is that unification of types involving => isn’t done by simple unification, but instead by bi-implication for constraints, so while you can write some types with them, you typically can’t build inhabitants.

]]>