Групи новин: comp.lang.haskell
Від: Dirk Thierbach <dthierb...@usenet.arcornews.de>
Дата: Sat, 13 Sep 2008 08:06:08 +0200
Локально: Сб 13 Вер 2008 09:06
Тема: Re: Difficulty deriving a general type for combinator
Simon Richard Clarkstone <s.r.clarkst...@dunelm.org.uk> wrote:
> Suppose I have a set of functions like these: That's more or less exactly what you need, though tf1 and tf2 cannot be > 2app_id_maybe :: (forall a. a -> Maybe a) -> (b,c) -> (Maybe b,Maybe c) > 2app_maybe_id :: (forall a. Maybe a -> a) -> (Maybe b,Maybe c) -> (b,c) > 2app_id_list :: (forall a. a -> [a]) -> (b, c) -> ([b], [c]) > 2app_id_listlist :: (forall a. a -> [[a]]) -> (b, c) -> ([[b]], [[c]]) > 2app_list_id :: (forall a. [a] -> a) -> ([b], [c]) -> (b, c) > Well, since their code are textually identical one should obviously > 2app f (x, y) = (f x, f y) > But what type does it have? The inferred type is: > 2app :: (a -> b) -> (a, a) -> (b, b) > But that isn't general enough, so I want to annotate the type. I can't > app2 :: (tf1 :: * -> *, tf2 :: * -> *) => (forall a. tf1 a -> tf2 a) -> > tf1 and tf2 are "type functions" of kind * -> *, more general than just predicates (typeclass related), but, as you say, must be "type functions". There's an extension of the typed lambda calculus called "System F" that allows such type functions. Unfortunately, it turns out that then a lot of decision problems about typing become undecidable, and also it is no longer guaranteed that every term can be assigned a most general type, so type inference goes out of the window. For these reasons, Haskell is rather restricted compared to System F: - It can infer only types without forall-quantifiers. app2 :: forall tf1 tf2 b c. And this would work for instances like app2' :: (forall a. [a] -> Maybe a) -> ([b], [c]) -> (Maybe b, Maybe c) but since "type functions" are restricted to constructors, there's app2' :: (Int -> Int) -> (Int, Int) -> (Int, Int) will also fail. You can simulate all that to some degree by defining a So with this example you have hit the spot where the Haskell type system twice f x = f (f x) is the more famous example for the same phenomenon. There are languages like Cayenne which implement full System F, but as The good news is that this kind of problem happens *very* rarely - Dirk Ви мусите увійти перед публікацією повідомлень.
Аби надіслати допис, будь ласка, спочатку приєднайтеся до цієї групи.
Будь ласка, поновіть своє прізвисько на сторінці налаштування передплати перед тим, як надіслати свій допис.
У вас немає права надсилання дописів до цієї групи.
| ||||||||||||||