Nicholls, Mark nicholls.mark at vimn.com
Fri May 29 16:19:15 UTC 2015

My actual use case is a bit more complex than just a repeating [Integer, Integer, Integer, Integer, Integer,...]

And in fact the recursion is not even repeated segments of a list...hmmm....or is it?.....not sure....lets say it isnt...for the moment.

At the moment it feels more like a recursive Tree type... a nice unrecursive one would be

mytree :: MyTree 'Branch '[ 'Leaf Integer, 'Branch '[ 'Leaf String, 'Leaf Bool ] ]
mytree = ....

Obviously we can construct recursive trees with recursive functions...that leads to recursive types...and BOOOM

I'm not sure I understand your example though....or if it helps in the above example....its all "a"s...I need a's and b's.

I know OF "fix"....and how we can use it to stratify (?) recursive structures....so...the question is whether we can "Fix" the above somehow.

There is I believe a "Fix" type....which makes my head hurt even more.

From: Richard Eisenberg [mailto:eir at cis.upenn.edu]
Sent: 29 May 2015 5:01 PM
To: Nicholls, Mark

GHC stubbornly refuses to allow infinite types, although I don't know of a good theoretical reason why. (From a practical standpoint, with infinite types, GHC would be very likely to hang, though that could be avoided with enough engineering, I think.) Your best bet here is, in my view, not to use promoted [] to index your list type, but instead something like

> data List a = Cons a (List a) | Tail [a]

where the Tail constructor marks a (possibly-empty) infinitely-repeating tail of a list. Instead of the infinite (repeat Integer) list, you would just have Tail [Integer], which is much better behaved. I haven't tried to build an indexed list from such a beast, though...

Richard

On May 29, 2015, at 11:47 AM, "Nicholls, Mark" <nicholls.mark at vimn.com<mailto:nicholls.mark at vimn.com>> wrote:

Hello,

If I were trying to do something like creating types like....

> {-# LANGUAGE DataKinds #-}
> {-# LANGUAGE ExplicitForAll #-}
> {-# LANGUAGE FlexibleContexts #-}
> {-# LANGUAGE FlexibleInstances #-}
> {-# LANGUAGE MultiParamTypeClasses #-}
> {-# LANGUAGE PolyKinds #-}
> {-# LANGUAGE StandaloneDeriving #-}
> {-# LANGUAGE TypeFamilies #-}
> {-# LANGUAGE TypeOperators #-}
> {-# LANGUAGE UndecidableInstances #-}
> {-# LANGUAGE ScopedTypeVariables #-}

> data MyList a where
>   MyEnd :: MyList '[]
>   MyCons :: a -> MyList b -> MyList (a ': b)

> mysimplelist :: MyList '[Integer]
> mysimplelist = MyCons 1 (MyEnd)

> myrecursivelist = MyCons 1 myrecursivelist

Cafe2.lhs:23:30:
Occurs check: cannot construct the infinite type: b ~ a : b
Expected type: MyList b
Actual type: MyList (a : b)
Relevant bindings include
myrecursivelist :: MyList (a : b) (bound at Cafe2.lhs:23:3)
In the second argument of 'MyCons', namely 'myrecursivelist'
In the expression: MyCons 1 myrecursivelist

can I "fix" this somehow?

I obviously want the type of myrecursivelist to be
MyList  '[Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer,.....]

Something like a completely nonsensical...

MyList  (Fix (Integer ': ))

P.S.

Yes, I barely understand "fix" as a function, let alone a data type.

CONFIDENTIALITY NOTICE

This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited.

While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.

Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us.

MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe.  MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.
_______________________________________________

CONFIDENTIALITY NOTICE

This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited.

While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data.

Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us.

MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe.  MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.
-------------- next part --------------
An HTML attachment was scrubbed...