
Hello Café, Is there any way to overcome this other way then by introducing some helper data types etc. etc.? We have: Prelude> :t ([head, last, head, last, head, last]) ([head, last, head, last, head, last]) :: [[a] -> a] Prelude> :t (\(h:t) -> head t) (\(h:t) -> head t) :: [a] -> a Prelude> :t ((\(h:t) -> head t) [head, last, head, last, head, last]) ((\(h:t) -> head t) [head, last, head, last, head, last]) :: [a] -> a But we have an error of infinite type construction for Prelude> :t ((\(h:t) -> h t) [head,tail, head, tail, head, tail]) Well I can overcome this by encoding functions into data types and then performing "conversion" back and forth, nevertheless, is there any way how to overcome this? My real problem is not about head/tail, but head/tail is the simplest way how to explain. Thanks for any references, Dušan

On Fri, 07 Mar 2014 07:57:09 +0100, Kolář Dušan
But we have an error of infinite type construction for
Prelude> :t ((\(h:t) -> h t) [head,tail, head, tail, head, tail])
Well I can overcome this by encoding functions into data types and then performing "conversion" back and forth, nevertheless, is there any way how to overcome this?
It seems like you need heterogenous collections[0] Regards, Henk-Jan van Tuyl [0] http://www.haskell.org/haskellwiki/Heterogenous_collections -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

Well my fault, the example should have been like this: We have and error of infinite type for Prelude> :t ((\(h:t) -> h t) [head, last, head, last, head, last]) Of course, head and tail are incompatible on type level... Dušan
On Fri, 07 Mar 2014 07:57:09 +0100, Kolář Dušan
wrote: : :
But we have an error of infinite type construction for
Prelude> :t ((\(h:t) -> h t) [head,tail, head, tail, head, tail])
Well I can overcome this by encoding functions into data types and then performing "conversion" back and forth, nevertheless, is there any way how to overcome this?
It seems like you need heterogenous collections[0]
Regards, Henk-Jan van Tuyl
[0] http://www.haskell.org/haskellwiki/Heterogenous_collections
-- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/
http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

We have and error of infinite type for Prelude> :t ((\(h:t) -> h t) [head, last, head, last, head, last])
Of course, head and tail are incompatible on type level...
It seems like you need heterogenous collections[0]
Well the error pops up much earlier than that, see: Prelude> :t (\(h:t) -> h t)
Regards, Henk-Jan van Tuyl
[0] http://www.haskell.org/haskellwiki/Heterogenous_collections
-- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/
http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --
-- | | UMPA - ENS Lyon | Mél: vbeffara@ens-lyon.fr | | Vincent Beffara | 46 allée d'Italie | Tél: (+33) 4 72 72 85 25 | | | 69364 Lyon Cedex 07 | Fax: (+33) 4 72 72 84 80 |

Yes, it is. the reason is, as I think, the following from application h t we can derive t :: a h :: t1 -> t2 after unification t :: a h :: a -> t2 now (h:t) t :: [e] h :: e merging t:: a ~ [e] -> a == [e] and it follows h :: [e] -> t2 h :: e which would give infinite type for unification. Nevertheless, from the example it is obvious, that for particular case, it is fine. We can explicitly type: h :: [a] -> a t :: [[a] -> a] for (h:t) it is OK h :: e ~ [a]->a and t :: [e] ~ [[a]->a] e.g. e == [a]->a and h :: e and t ::[e], which is fine Now, h t h :: [a] -> a t :: [[b] -> b] and it is fine, as type a == [b] -> b of course, monomorphism restriction would lead to infinite type again. So, the question is, how for the particular case force the inference this way, to break the restriction... Dušan On 03/07/2014 09:33 AM, Vincent Beffara wrote:
We have and error of infinite type for Prelude> :t ((\(h:t) -> h t) [head, last, head, last, head, last])
Of course, head and tail are incompatible on type level...
It seems like you need heterogenous collections[0] Well the error pops up much earlier than that, see:
Prelude> :t (\(h:t) -> h t)
Regards, Henk-Jan van Tuyl
[0] http://www.haskell.org/haskellwiki/Heterogenous_collections
-- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/
http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

The problem is, that the type parameter 'a' of the functions in the list is
fixed. You can work around that with RankNTypes:
newtype Wrap = Wrap { unwrap :: forall a. [a] -> a }
unwrap $ (\(h:t) -> (unwrap h) t) [Wrap head, Wrap last]
This specializes the type of the functions at every point of use separately.
On 7 March 2014 09:14, Kolář Dušan
Well my fault, the example should have been like this:
We have and error of infinite type for Prelude> :t ((\(h:t) -> h t) [head, last, head, last, head, last])
Of course, head and tail are incompatible on type level...
Dušan
On Fri, 07 Mar 2014 07:57:09 +0100, Kolář Dušan
wrote:
: :
But we have an error of infinite type construction for
Prelude> :t ((\(h:t) -> h t) [head,tail, head, tail, head, tail])
Well I can overcome this by encoding functions into data types and then performing "conversion" back and forth, nevertheless, is there any way how to overcome this?
It seems like you need heterogenous collections[0]
Regards, Henk-Jan van Tuyl
[0] http://www.haskell.org/haskellwiki/Heterogenous_collections
-- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/
http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Thanks. I think this is the simplest solution. Dušan On 03/07/2014 10:37 AM, Tobias Brandt wrote:
The problem is, that the type parameter 'a' of the functions in the list is fixed. You can work around that with RankNTypes:
newtype Wrap = Wrap { unwrap :: forall a. [a] -> a }
unwrap $ (\(h:t) -> (unwrap h) t) [Wrap head, Wrap last]
This specializes the type of the functions at every point of use separately.
On 7 March 2014 09:14, Kolář Dušan
mailto:kolar@fit.vutbr.cz> wrote: Well my fault, the example should have been like this:
We have and error of infinite type for Prelude> :t ((\(h:t) -> h t) [head, last, head, last, head, last])
Of course, head and tail are incompatible on type level...
Dušan
On Fri, 07 Mar 2014 07:57:09 +0100, Kolář Dušan
mailto:kolar@fit.vutbr.cz> wrote: : :
But we have an error of infinite type construction for
Prelude> :t ((\(h:t) -> h t) [head,tail, head, tail, head, tail])
Well I can overcome this by encoding functions into data types and then performing "conversion" back and forth, nevertheless, is there any way how to overcome this?
It seems like you need heterogenous collections[0]
Regards, Henk-Jan van Tuyl
[0] http://www.haskell.org/haskellwiki/Heterogenous_collections
-- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/
http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto:Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Dušan Kolář
-
Henk-Jan van Tuyl
-
Kolář Dušan
-
Tobias Brandt
-
Vincent Beffara