<div dir="ltr">Would this work for you?<br><br>data BiList a b<br>     = Empty<br>     | a :# (BiList b a)<br><br>infixr 5 :#<br><br>blah :: BiList Char Int<br>blah = 'a' :# 1 :# 'a' :# Empty<br><br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, Apr 2, 2014 at 9:52 PM, Jacek Dudek <span dir="ltr"><<a href="mailto:jzdudek@gmail.com" target="_blank">jzdudek@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-- As an exercise I wanted to define a datatype that is an alternating<br>
list of elements of two different types. The best that I could do are<br>
the type definitions below:<br>
<br>
module BiList<br>
    ( BiList (..)<br>
    , AList (EmptyA)<br>
    , BList (EmptyB)<br>
    ) where<br>
<br>
data BiList a b<br>
    = Empty<br>
    | BA (AList a b)<br>
    | BB (BList a b)<br>
<br>
data AList a b<br>
    = EmptyA<br>
    | AL a (BList a b)<br>
<br>
data BList a b<br>
    = EmptyB<br>
    | BL b (AList a b)<br>
<br>
(<#) :: a -> (BList a b) -> (AList a b)<br>
a <# bs = AL a bs<br>
<br>
(<@) :: b -> (AList a b) -> (BList a b)<br>
b <@ as = BL b as<br>
<br>
infixr 5 <#<br>
infixr 5 <@<br>
<br>
example :: BiList Int Char<br>
example = BA $ 1 <# 'a' <@ 2 <# 'b' <@ 3 <# 'c' <@ 4 <# 'd' <@ EmptyA<br>
<br>
-- There are two things that I don't like about this implementation.<br>
<br>
-- (1) The BA and BB constructors that must be applied on top of<br>
instances of (AList a b) and (BList a b) to lift them to be of type<br>
(BiList a b).<br>
<br>
-- (2) Having three different constructors for an empty list: Empty,<br>
EmptyA, EmptyB, where ideally I would just have one.<br>
<br>
-- Is it possible to get around either of these annoyances with some<br>
type theory gymnastics? Maybe something like the function fromIntegral<br>
(the mechanics of which I don't really understand at this point)?<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>