-- Author: Andy Stewart <lazycat.manatee@gmail.com>-- Maintainer: Andy Stewart <lazycat.manatee@gmail.com>-- -- Copyright (C) 2010 Andy Stewart, all rights reserved.-- -- This program 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-- any later version.-- -- This program 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 this program. If not, see <http://www.gnu.org/licenses/>.moduleManatee.Toolkit.General.BasicwhereimportControl.ArrowimportControl.Monadhiding(filterM,mapM)-- | Swap tuple.swap::(a,b)->(b,a)swap(a,b)=(b,a)-- | Try to swap tuple.ifSwap::Bool->(a,a)->(a,a)ifSwapbx=ifbthenswapxelsex-- | Duplicate current value with tuple.dup::a->(a,a)dupa=(a,a)-- | Transform Int to Doublei2d::Integrala=>a->Doublei2dv=fromIntegralv::Double-- | Integer to Int.integerToInt::Integer->IntintegerToIntt=fromIntegert::Int-- | Flip >>(<<)::Monadm=>mb->ma->mb(<<)=flip(>>)-- | Like LiftM2, but make function at middle of two arguments.liftM2'::Monadm=>ma->(a->b->c)->mb->mcliftM2'xsf=liftM2fxsliftM2_::Monadm=>(a->b->c)->ma->mb->m()liftM2_fxy=liftM2fxy>>return()-- | If monad.ifM::Monadm=>mBool->ma->ma->maifMfgh=f>>=\b->ifbthengelseh-- | If monad.ifF::Monadm=>a->(a->mBool)->(a->mb)->(a->mb)->mbifFafgh=fa>>=\b->ifbthengaelseha-- | When monad.whenM::Monadm=>mBool->m()->m()whenMfg=f>>=\x->whenxg-- | Unless monad.unlessM::Monadm=>mBool->m()->m()unlessMfg=f>>=\x->unlessxg-- | Zip'zip'::a->b->(a,b)zip'ab=(a,b)-- | ZipM'zipM'::Monadm=>ma->mb->m(a,b)zipM'=liftM2zip'-- | FirstMap.firstMap::(b->c)->[(b,d)]->[(c,d)]firstMap=map.first-- | Zip with map.zipMap::(a->b,a->c)->a->(b,c)zipMap(g,h)s=(gs,hs)-- | Unzip with map.unzipMap::(a->(b,c))->(a->b,a->c)unzipMaph=(fst.h,snd.h)-- | Trace.trace::((a,c)->(b,c))->a->btracefb=cwhere(c,d)=f(b,d)-- | Floor to multiple.floorToMultiple::Integrala=>a->a->afloorToMultiplexy=x-x`mod`y-- | Like a switch statement, and less cluttered than if else if-- -- > cond [ (t1,a1), (t2,a2), ... ]cond::Monadm=>[(Bool,m())]->m()cond[]=return()cond((True,action):_)=actioncond((False,_):rest)=condrest-- | Like a switch statement, and less cluttered than if else if -- -- > condM [ (t1,a1), (t2,a2), ... ]condM::Monadm=>[(mBool,m())]->m()condM[]=return()condM((test,action):rest)=test>>=\t->iftthenactionelsecondMrest