{-
List.hs
Copyright 2008 Matthew Sackman <matthew@wellquite.org>
This file is part of Session Types for Haskell.
Session Types for Haskell is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Session Types for Haskell is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Session Types for Haskell.
If not, see <http://www.gnu.org/licenses/>.
-}{-# LANGUAGE KindSignatures, GADTs, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances, OverlappingInstances #-}-- | Heterogeneous lists. This has been done many times, in many-- different ways. Explicit constructors are hidden deliberately.moduleControl.Concurrent.Session.ListwhereimportControl.Concurrent.Session.NumberdataNil::*whereNil::NildataCons::*->*->*whereCons::t->n->Constn-- | Find the length of a list.classListLengthlistlength|list->lengthwherelistLength::list->lengthinstanceListLengthNil(D0E)wherelistLengthNil=(D0E)instance(ListLengthnlen,Succlenlen')=>ListLength(Constn)len'wherelistLength(Cons_nxt)=tySucc.listLength$nxtinstanceShowNilwhereshowNil="Nil"instance(ListLengthnl,Succll',Shown,Showt)=>Show(Constn)whereshow(Consvalnxt)="Cons "++(showval)++" ("++(shownxt)++")"nil::Nilnil=Nilcons::(TyListn)=>t->n->(Constn)constn=ConstnclassTyListlinstanceTyListNilinstance(TyListnxt)=>TyList(Consvalnxt)-- | Index or update a listclassElemlstidxres|lstidx->reswheretyListElem::lst->idx->restyListUpdate::lst->idx->res->lstinstanceElem(Consresnxt)(D0E)reswheretyListElem(Consval_)_=valtyListUpdate(Cons_nxt)_val=(Consvalnxt)instance(Elemnxtidx'res,Predidxidx',SmallerThanidx'len,ListLengthnxtlen)=>Elem(Consvalnxt)idxreswheretyListElem(Cons_nxt)idx=tyListElemnxt(tyPredidx)tyListUpdate(Consvalnxt)idxval'=Consval(tyListUpdatenxt(tyPredidx)val')