[Haskell-cafe] recursive datakinds
Richard Eisenberg
eir at cis.upenn.edu
Fri May 29 16:01:04 UTC 2015
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> wrote:
> Hello,
>
> If I were trying to do something like creating types like….
>
>
> > {-# LANGUAGE DataKinds #-}
> > {-# LANGUAGE ExplicitForAll #-}
> > {-# LANGUAGE FlexibleContexts #-}
> > {-# LANGUAGE FlexibleInstances #-}
> > {-# LANGUAGE GADTs #-}
> > {-# 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)
>
> what about
>
> > 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.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150529/8fa7c1d7/attachment.html>
More information about the Haskell-Cafe
mailing list