[Haskell-cafe] recursive datakinds

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


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150529/2dd08c0f/attachment.html>


More information about the Haskell-Cafe mailing list