<s> import itertools <EOL> import functools <EOL> import operator <EOL> from . . lang import H <EOL> from . . lang import sig <EOL> from . . lang import t <EOL> from . . lang import L <EOL> from . . lang import __ <EOL> from . . lang import caseof <EOL> from . . lang import m <EOL> from . . lang import p <EOL> from Eq import Eq <EOL> from Ord import Ord <EOL> from Ord import Ordering <EOL> from Num import Num <EOL> from Num import Integral <EOL> from Maybe import Maybe <EOL> from Maybe import Just <EOL> from Maybe import Nothing <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def head ( xs ) : <EOL> """<STR_LIT>""" <EOL> return xs [ <NUM_LIT:0> ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def last ( xs ) : <EOL> """<STR_LIT>""" <EOL> return xs [ - <NUM_LIT:1> ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def tail ( xs ) : <EOL> """<STR_LIT>""" <EOL> if null ( xs ) : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> return xs [ <NUM_LIT:1> : ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def init ( xs ) : <EOL> """<STR_LIT>""" <EOL> if null ( xs ) : <EOL> raise IndexError ( "<STR_LIT>" ) <EOL> return xs [ : - <NUM_LIT:1> ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> t ( Maybe , ( "<STR_LIT:a>" , [ "<STR_LIT:a>" ] ) ) ) <EOL> def uncons ( xs ) : <EOL> """<STR_LIT>""" <EOL> return Just ( ( head ( xs ) , tail ( xs ) ) ) if not null ( xs ) else Nothing <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> bool ) <EOL> def null ( xs ) : <EOL> """<STR_LIT>""" <EOL> return ~ ( caseof ( xs ) <EOL> | m ( m . y ^ m . ys ) >> False <EOL> | m ( m . ys ) >> True ) <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> int ) <EOL> def length ( xs ) : <EOL> """<STR_LIT>""" <EOL> return len ( xs ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:b>" ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] ) <EOL> def map ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ itertools . imap ( f , xs ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def reverse ( xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( x for x in xs [ : : - <NUM_LIT:1> ] ) ] <EOL> @ sig ( H / "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def intersperse ( x , xs ) : <EOL> """<STR_LIT>""" <EOL> def __intersperse ( x , xs ) : <EOL> for y in init ( xs ) : <EOL> yield y <EOL> yield x <EOL> yield last ( xs ) <EOL> if null ( xs ) : <EOL> return xs <EOL> return L [ __intersperse ( x , xs ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ [ "<STR_LIT:a>" ] ] >> [ "<STR_LIT:a>" ] ) <EOL> def intercalate ( xs , xss ) : <EOL> """<STR_LIT>""" <EOL> return concat ( intersperse ( xs , xss ) ) <EOL> @ sig ( H / [ [ "<STR_LIT:a>" ] ] >> [ [ "<STR_LIT:a>" ] ] ) <EOL> def transpose ( xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( L [ x ] for x in itertools . izip ( * xs ) ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ [ "<STR_LIT:a>" ] ] ) <EOL> def subsequences ( xs ) : <EOL> """<STR_LIT>""" <EOL> ret = L [ [ L [ [ ] ] ] ] <EOL> for r , _ in enumerate ( xs ) : <EOL> ret += L [ ( L [ x ] for x in itertools . combinations ( xs , r + <NUM_LIT:1> ) ) ] <EOL> return ret <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ [ "<STR_LIT:a>" ] ] ) <EOL> def permutations ( xs ) : <EOL> """<STR_LIT>""" <EOL> if null ( xs ) : <EOL> return L [ [ ] ] <EOL> return L [ ( L [ x ] for x in itertools . permutations ( xs ) ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:b>" >> "<STR_LIT:a>" >> "<STR_LIT:b>" ) >> "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> "<STR_LIT:b>" ) <EOL> def foldl ( f , z , xs ) : <EOL> """<STR_LIT>""" <EOL> return reduce ( f , xs , z ) <EOL> @ sig ( H / ( H / "<STR_LIT:b>" >> "<STR_LIT:a>" >> "<STR_LIT:b>" ) >> "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> "<STR_LIT:b>" ) <EOL> def foldl_ ( f , z , xs ) : <EOL> """<STR_LIT>""" <EOL> return foldl ( f , z , xs ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> "<STR_LIT:a>" ) >> [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def foldl1 ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> return foldl ( f , xs [ <NUM_LIT:0> ] , xs [ <NUM_LIT:1> : ] ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> "<STR_LIT:a>" ) >> [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def foldl1_ ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> return foldl1 ( f , xs [ <NUM_LIT:0> ] , xs [ <NUM_LIT:1> : ] ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:b>" >> "<STR_LIT:b>" ) >> "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> "<STR_LIT:b>" ) <EOL> def foldr ( f , z , xs ) : <EOL> """<STR_LIT>""" <EOL> return ~ ( caseof ( xs ) <EOL> | m ( L [ [ ] ] ) >> z <EOL> | m ( m . a ^ m . b ) >> f ( p . a , foldr ( f , z , p . b ) ) ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> "<STR_LIT:a>" ) >> [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def foldr1 ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> return foldr ( f , xs [ <NUM_LIT:0> ] , xs [ <NUM_LIT:1> : ] ) <EOL> @ sig ( H / [ [ "<STR_LIT:a>" ] ] >> [ "<STR_LIT:a>" ] ) <EOL> def concat ( xss ) : <EOL> """<STR_LIT>""" <EOL> def __concat ( xss ) : <EOL> for xs in xss : <EOL> for x in xs : <EOL> yield x <EOL> return L [ __concat ( xss ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> [ "<STR_LIT:b>" ] ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] ) <EOL> def concatMap ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> return concat ( map ( f , xs ) ) <EOL> @ sig ( H / [ bool ] >> bool ) <EOL> def and_ ( xs ) : <EOL> """<STR_LIT>""" <EOL> return False not in xs <EOL> @ sig ( H / [ bool ] >> bool ) <EOL> def or_ ( xs ) : <EOL> """<STR_LIT>""" <EOL> return True in xs <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> bool ) <EOL> def any ( p , xs ) : <EOL> """<STR_LIT>""" <EOL> return True in ( ( p ( x ) for x in xs ) ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> bool ) <EOL> def all ( p , xs ) : <EOL> """<STR_LIT>""" <EOL> return False not in ( ( p ( x ) for x in xs ) ) <EOL> @ sig ( H [ ( Num , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def sum ( xs ) : <EOL> """<STR_LIT>""" <EOL> return functools . reduce ( operator . add , xs , <NUM_LIT:0> ) <EOL> @ sig ( H [ ( Num , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def product ( xs ) : <EOL> """<STR_LIT>""" <EOL> return functools . reduce ( operator . mul , xs , <NUM_LIT:1> ) <EOL> @ sig ( H [ ( Ord , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def minimum ( xs ) : <EOL> """<STR_LIT>""" <EOL> return min ( xs ) <EOL> @ sig ( H [ ( Ord , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def maximum ( xs ) : <EOL> """<STR_LIT>""" <EOL> return max ( xs ) <EOL> @ sig ( H / ( H / "<STR_LIT:b>" >> "<STR_LIT:a>" >> "<STR_LIT:b>" ) >> "<STR_LIT:b>" >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] ) <EOL> def scanl ( f , z , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> "<STR_LIT:a>" ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def scanl1 ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> "<STR_LIT:b>" ) >> "<STR_LIT:b>" >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] ) <EOL> def scanr ( f , z , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> "<STR_LIT:a>" ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def scanr1 ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:x>" >> ( "<STR_LIT:a>" , "<STR_LIT:y>" ) ) >> "<STR_LIT:a>" >> [ "<STR_LIT:x>" ] >> ( "<STR_LIT:a>" , [ "<STR_LIT:y>" ] ) ) <EOL> def mapAccumL ( xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:x>" >> ( "<STR_LIT:a>" , "<STR_LIT:y>" ) ) >> "<STR_LIT:a>" >> [ "<STR_LIT:x>" ] >> ( "<STR_LIT:a>" , [ "<STR_LIT:y>" ] ) ) <EOL> def mapAccumR ( xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" ) >> "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] ) <EOL> def iterate ( f , x ) : <EOL> """<STR_LIT>""" <EOL> def __iterate ( f , x ) : <EOL> while True : <EOL> yield x <EOL> x = f ( x ) <EOL> return L [ __iterate ( f , x ) ] <EOL> @ sig ( H / "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] ) <EOL> def repeat ( x ) : <EOL> """<STR_LIT>""" <EOL> def __repeat ( x ) : <EOL> while True : <EOL> yield x <EOL> return L [ __repeat ( x ) ] <EOL> @ sig ( H / int >> "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] ) <EOL> def replicate ( n , x ) : <EOL> """<STR_LIT>""" <EOL> def __replicate ( n , x ) : <EOL> for _ in range ( n ) : <EOL> yield x <EOL> return L [ __replicate ( n , x ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def cycle ( x ) : <EOL> """<STR_LIT>""" <EOL> def __cycle ( x ) : <EOL> while True : <EOL> for i in x : <EOL> yield i <EOL> return L [ __cycle ( x ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:b>" >> t ( Maybe , ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) ) >> "<STR_LIT:b>" >> [ "<STR_LIT:a>" ] ) <EOL> def unfoldr ( f , x ) : <EOL> """<STR_LIT>""" <EOL> y = f ( x ) <EOL> if y == Nothing : <EOL> return L [ [ ] ] <EOL> return y [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ^ unfoldr ( f , y [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> @ sig ( H / int >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def take ( n , xs ) : <EOL> """<STR_LIT>""" <EOL> return xs [ : n ] <EOL> @ sig ( H / int >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def drop ( n , xs ) : <EOL> """<STR_LIT>""" <EOL> return xs [ n : ] <EOL> @ sig ( H / int >> [ "<STR_LIT:a>" ] >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:a>" ] ) ) <EOL> def splitAt ( n , xs ) : <EOL> """<STR_LIT>""" <EOL> return ( xs [ : n ] , xs [ n : ] ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def takeWhile ( p , xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ itertools . takewhile ( p , xs ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def dropWhile ( p , xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ itertools . dropwhile ( p , xs ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def dropWhileEnd ( p , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:a>" ] ) ) <EOL> def span ( p , xs ) : <EOL> """<STR_LIT>""" <EOL> front = takeWhile ( p , xs ) <EOL> rest = xs [ len ( front ) : ] <EOL> return front , rest <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:a>" ] ) ) <EOL> def break_ ( p , xs ) : <EOL> """<STR_LIT>""" <EOL> inv = ( lambda x : not p ( x ) ) ** ( H / "<STR_LIT:a>" >> bool ) <EOL> return span ( inv , xs ) <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> t ( Maybe , [ "<STR_LIT:a>" ] ) ) <EOL> def stripPrefix ( xs , ys ) : <EOL> """<STR_LIT>""" <EOL> if isPrefixOf ( xs , ys ) : <EOL> return Just ( ys [ len ( xs ) ] ) <EOL> return Nothing <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ [ "<STR_LIT:a>" ] ] ) <EOL> def group ( xs ) : <EOL> """<STR_LIT>""" <EOL> return groupBy ( xs , ( __ == __ ) ) <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ [ "<STR_LIT:a>" ] ] ) <EOL> def inits ( xs ) : <EOL> """<STR_LIT>""" <EOL> if null ( xs ) : <EOL> return L [ [ xs ] ] <EOL> return L [ [ L [ [ ] ] ] ] + L [ ( xs [ : n + <NUM_LIT:1> ] for n , _ in enumerate ( xs ) ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ [ "<STR_LIT:a>" ] ] ) <EOL> def tails ( xs ) : <EOL> """<STR_LIT>""" <EOL> if null ( xs ) : <EOL> return L [ [ L [ [ ] ] ] ] <EOL> return L [ ( xs [ n : ] for n , _ in enumerate ( xs ) ) ] + L [ [ L [ [ ] ] ] ] <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> bool ) <EOL> def isPrefixOf ( xs , ys ) : <EOL> """<STR_LIT>""" <EOL> return xs == ys [ : len ( xs ) ] <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> bool ) <EOL> def isSuffixOf ( xs , ys ) : <EOL> """<STR_LIT>""" <EOL> return xs == ys [ - len ( xs ) : ] <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> bool ) <EOL> def isInfixOf ( xs , ys ) : <EOL> """<STR_LIT>""" <EOL> return any ( isPrefixOf ( xs ) , tails ( ys ) ) <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> bool ) <EOL> def isSubsequenceOf ( x , y ) : <EOL> """<STR_LIT>""" <EOL> return elem ( x , subsequences ( y ) ) <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> bool ) <EOL> def elem ( x , xs ) : <EOL> """<STR_LIT>""" <EOL> return x in xs <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> bool ) <EOL> def notElem ( x , xs ) : <EOL> """<STR_LIT>""" <EOL> return not elem ( x , xs ) <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / "<STR_LIT:a>" >> [ ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ] >> t ( Maybe , "<STR_LIT:b>" ) ) <EOL> def lookup ( key , assocs ) : <EOL> """<STR_LIT>""" <EOL> for k , value in assocs : <EOL> if k == key : <EOL> return Just ( value ) <EOL> return Nothing <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> t ( Maybe , "<STR_LIT:a>" ) ) <EOL> def find ( p , xs ) : <EOL> """<STR_LIT>""" <EOL> for x in xs : <EOL> if p ( x ) : <EOL> return Just ( x ) <EOL> return Nothing <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def filter ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ itertools . ifilter ( f , xs ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:a>" ] ) ) <EOL> def partition ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> yes , no = [ ] , [ ] <EOL> for item in xs : <EOL> if f ( item ) : <EOL> yes . append ( item ) <EOL> else : <EOL> no . append ( item ) <EOL> return L [ yes ] , L [ no ] <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> t ( Maybe , int ) ) <EOL> def elemIndex ( x , xs ) : <EOL> """<STR_LIT>""" <EOL> for i , a in enumerate ( xs ) : <EOL> if a == x : <EOL> return Just ( i ) <EOL> return Nothing <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> [ int ] ) <EOL> def elemIndices ( x , xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( i for i , a in enumerate ( xs ) if a == x ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> t ( Maybe , int ) ) <EOL> def findIndex ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> for i , x in enumerate ( xs ) : <EOL> if f ( x ) : <EOL> return Just ( i ) <EOL> return Nothing <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> [ int ] ) <EOL> def findIndicies ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( i for i , x in enumerate ( xs ) if f ( x ) ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ] ) <EOL> def zip ( xs , ys ) : <EOL> """<STR_LIT>""" <EOL> return L [ itertools . izip ( xs , ys ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] >> [ ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" ) ] ) <EOL> def zip3 ( a , b , c ) : <EOL> """<STR_LIT>""" <EOL> return L [ itertools . izip ( a , b , c ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] >> [ "<STR_LIT:d>" ] >> [ ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" ) ] ) <EOL> def zip4 ( a , b , c , d ) : <EOL> """<STR_LIT>""" <EOL> return L [ itertools . izip ( a , b , c , d ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] >> [ "<STR_LIT:d>" ] >> [ "<STR_LIT:e>" ] >> <EOL> [ ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" , "<STR_LIT:e>" ) ] ) <EOL> def zip5 ( a , b , c , d , e ) : <EOL> """<STR_LIT>""" <EOL> return L [ itertools . izip ( a , b , c , d , e ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] >> [ "<STR_LIT:d>" ] >> [ "<STR_LIT:e>" ] >> [ "<STR_LIT:f>" ] >> <EOL> [ ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" , "<STR_LIT:e>" , "<STR_LIT:f>" ) ] ) <EOL> def zip6 ( a , b , c , d , e , f ) : <EOL> """<STR_LIT>""" <EOL> return L [ itertools . izip ( a , b , c , d , e , f ) ] <EOL> @ sig ( H / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] >> [ "<STR_LIT:d>" ] >> [ "<STR_LIT:e>" ] >> [ "<STR_LIT:f>" ] >> [ "<STR_LIT:g>" ] >> <EOL> [ ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" , "<STR_LIT:e>" , "<STR_LIT:f>" , "<STR_LIT:g>" ) ] ) <EOL> def zip7 ( a , b , c , d , e , f , g ) : <EOL> """<STR_LIT>""" <EOL> return L [ itertools . izip ( a , b , c , d , e , f , g ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:b>" >> "<STR_LIT:c>" ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] ) <EOL> def zipWith ( fn , xs , ys ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( fn ( * s ) for s in zip ( xs , ys ) ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:b>" >> "<STR_LIT:c>" >> "<STR_LIT:d>" ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] >> [ "<STR_LIT:d>" ] ) <EOL> def zipWith3 ( fn , a , b , c ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( fn ( * s ) for s in zip3 ( a , b , c ) ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:b>" >> "<STR_LIT:c>" >> "<STR_LIT:d>" >> "<STR_LIT:e>" ) >> <EOL> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] >> [ "<STR_LIT:d>" ] >> [ "<STR_LIT:e>" ] ) <EOL> def zipWith4 ( fn , a , b , c , d ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( fn ( * s ) for s in zip4 ( a , b , c , d ) ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:b>" >> "<STR_LIT:c>" >> "<STR_LIT:d>" >> "<STR_LIT:e>" >> "<STR_LIT:f>" ) >> <EOL> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] >> [ "<STR_LIT:d>" ] >> [ "<STR_LIT:e>" ] >> [ "<STR_LIT:f>" ] ) <EOL> def zipWith5 ( fn , a , b , c , d , e ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( fn ( * s ) for s in zip5 ( a , b , c , d , e ) ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:b>" >> "<STR_LIT:c>" >> "<STR_LIT:d>" >> "<STR_LIT:e>" >> "<STR_LIT:f>" >> "<STR_LIT:g>" ) >> <EOL> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] >> [ "<STR_LIT:d>" ] >> [ "<STR_LIT:e>" ] >> [ "<STR_LIT:f>" ] >> [ "<STR_LIT:g>" ] ) <EOL> def zipWith6 ( fn , a , b , c , d , e , f ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( fn ( * s ) for s in zip6 ( a , b , c , d , e , f ) ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:b>" >> "<STR_LIT:c>" >> "<STR_LIT:d>" >> "<STR_LIT:e>" >> "<STR_LIT:f>" >> "<STR_LIT:g>" >> "<STR_LIT:h>" ) >> <EOL> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:b>" ] >> [ "<STR_LIT:c>" ] >> [ "<STR_LIT:d>" ] >> [ "<STR_LIT:e>" ] >> [ "<STR_LIT:f>" ] >> [ "<STR_LIT:g>" ] >> [ "<STR_LIT:h>" ] ) <EOL> def zipWith7 ( fn , a , b , c , d , e , f ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( fn ( * s ) for s in zip7 ( a , b , c , d , e , f ) ) ] <EOL> @ sig ( H / [ ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ] >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:b>" ] ) ) <EOL> def unzip ( xs ) : <EOL> """<STR_LIT>""" <EOL> a = L [ ( i [ <NUM_LIT:0> ] for i in xs ) ] <EOL> b = L [ ( i [ <NUM_LIT:1> ] for i in xs ) ] <EOL> return a , b <EOL> @ sig ( H / [ ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" ) ] >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:b>" ] , [ "<STR_LIT:c>" ] ) ) <EOL> def unzip3 ( xs ) : <EOL> """<STR_LIT>""" <EOL> a = L [ ( i [ <NUM_LIT:0> ] for i in xs ) ] <EOL> b = L [ ( i [ <NUM_LIT:1> ] for i in xs ) ] <EOL> c = L [ ( i [ <NUM_LIT:2> ] for i in xs ) ] <EOL> return a , b , c <EOL> @ sig ( H / [ ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" ) ] >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:b>" ] , [ "<STR_LIT:c>" ] , [ "<STR_LIT:d>" ] ) ) <EOL> def unzip4 ( xs ) : <EOL> """<STR_LIT>""" <EOL> a = L [ ( i [ <NUM_LIT:0> ] for i in xs ) ] <EOL> b = L [ ( i [ <NUM_LIT:1> ] for i in xs ) ] <EOL> c = L [ ( i [ <NUM_LIT:2> ] for i in xs ) ] <EOL> d = L [ ( i [ <NUM_LIT:3> ] for i in xs ) ] <EOL> return a , b , c , d <EOL> @ sig ( H / [ ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" , "<STR_LIT:e>" ) ] >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:b>" ] , [ "<STR_LIT:c>" ] , [ "<STR_LIT:d>" ] , [ "<STR_LIT:e>" ] ) ) <EOL> def unzip5 ( xs ) : <EOL> """<STR_LIT>""" <EOL> a = L [ ( i [ <NUM_LIT:0> ] for i in xs ) ] <EOL> b = L [ ( i [ <NUM_LIT:1> ] for i in xs ) ] <EOL> c = L [ ( i [ <NUM_LIT:2> ] for i in xs ) ] <EOL> d = L [ ( i [ <NUM_LIT:3> ] for i in xs ) ] <EOL> e = L [ ( i [ <NUM_LIT:4> ] for i in xs ) ] <EOL> return a , b , c , d , e <EOL> @ sig ( H / [ ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" , "<STR_LIT:e>" , "<STR_LIT:f>" ) ] <EOL> >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:b>" ] , [ "<STR_LIT:c>" ] , [ "<STR_LIT:d>" ] , [ "<STR_LIT:e>" ] , [ "<STR_LIT:f>" ] ) ) <EOL> def unzip6 ( xs ) : <EOL> """<STR_LIT>""" <EOL> a = L [ ( i [ <NUM_LIT:0> ] for i in xs ) ] <EOL> b = L [ ( i [ <NUM_LIT:1> ] for i in xs ) ] <EOL> c = L [ ( i [ <NUM_LIT:2> ] for i in xs ) ] <EOL> d = L [ ( i [ <NUM_LIT:3> ] for i in xs ) ] <EOL> e = L [ ( i [ <NUM_LIT:4> ] for i in xs ) ] <EOL> f = L [ ( i [ <NUM_LIT:5> ] for i in xs ) ] <EOL> return a , b , c , d , e , f <EOL> @ sig ( H / [ ( "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" , "<STR_LIT:e>" , "<STR_LIT:f>" , "<STR_LIT:g>" ) ] <EOL> >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:b>" ] , [ "<STR_LIT:c>" ] , [ "<STR_LIT:d>" ] , [ "<STR_LIT:e>" ] , [ "<STR_LIT:f>" ] , [ "<STR_LIT:g>" ] ) ) <EOL> def unzip7 ( xs ) : <EOL> """<STR_LIT>""" <EOL> a = L [ ( i [ <NUM_LIT:0> ] for i in xs ) ] <EOL> b = L [ ( i [ <NUM_LIT:1> ] for i in xs ) ] <EOL> c = L [ ( i [ <NUM_LIT:2> ] for i in xs ) ] <EOL> d = L [ ( i [ <NUM_LIT:3> ] for i in xs ) ] <EOL> e = L [ ( i [ <NUM_LIT:4> ] for i in xs ) ] <EOL> f = L [ ( i [ <NUM_LIT:5> ] for i in xs ) ] <EOL> g = L [ ( i [ <NUM_LIT:6> ] for i in xs ) ] <EOL> return a , b , c , d , e , f , g <EOL> from String import lines <EOL> from String import words <EOL> from String import unlines <EOL> from String import unwords <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def nub ( xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( i for i in set ( xs ) ) ] <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def delete ( x , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def diff ( xs , ys ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def union ( xs , ys ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H [ ( Eq , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def intersect ( xs , ys ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H [ ( Ord , "<STR_LIT:a>" ) ] / [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def sort ( xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ sorted ( xs ) ] <EOL> @ sig ( H [ ( Ord , "<STR_LIT:b>" ) ] / ( H / "<STR_LIT:a>" >> "<STR_LIT:b>" ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def sortOn ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H [ ( Ord , "<STR_LIT:a>" ) ] / "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def insert ( x , xs ) : <EOL> """<STR_LIT>""" <EOL> def __insert ( x , xs ) : <EOL> for i in xs : <EOL> if i > x : <EOL> yield x <EOL> yield i <EOL> return L [ __insert ( x , xs ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def nubBy ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> bool ) >> "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def deleteBy ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def deleteFirstBy ( f , xs , ys ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def unionBy ( f , xs , ys ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def intersectBy ( f , xs , ys ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> bool ) >> [ "<STR_LIT:a>" ] >> [ [ "<STR_LIT:a>" ] ] ) <EOL> def groupBy ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> return L [ ( L [ i [ <NUM_LIT:1> ] ] for i in itertools . groupby ( xs , keyfunc = f ) ) ] <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> Ordering ) >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def sortBy ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> Ordering ) >> "<STR_LIT:a>" >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def insertBy ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> Ordering ) >> [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def maximumBy ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> return max ( xs , key = f ) <EOL> @ sig ( H / ( H / "<STR_LIT:a>" >> "<STR_LIT:a>" >> Ordering ) >> [ "<STR_LIT:a>" ] >> "<STR_LIT:a>" ) <EOL> def minimumBy ( f , xs ) : <EOL> """<STR_LIT>""" <EOL> return min ( xs , key = f ) <EOL> @ sig ( H [ ( Num , "<STR_LIT:i>" ) ] / [ "<STR_LIT:a>" ] >> "<STR_LIT:i>" ) <EOL> def genericLength ( xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H [ Integral , "<STR_LIT:i>" ] / "<STR_LIT:i>" >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def genericTake ( n , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H [ Integral , "<STR_LIT:i>" ] / "<STR_LIT:i>" >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def genericDrop ( n , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H [ Integral , "<STR_LIT:i>" ] / "<STR_LIT:i>" >> [ "<STR_LIT:a>" ] >> ( [ "<STR_LIT:a>" ] , [ "<STR_LIT:a>" ] ) ) <EOL> def genericSplitAt ( n , xs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H [ Integral , "<STR_LIT:i>" ] / [ "<STR_LIT:a>" ] >> "<STR_LIT:i>" >> [ "<STR_LIT:a>" ] ) <EOL> def genericIndex ( xs , i ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> @ sig ( H [ Integral , "<STR_LIT:i>" ] / "<STR_LIT:i>" >> [ "<STR_LIT:a>" ] >> [ "<STR_LIT:a>" ] ) <EOL> def genericReplicate ( i , a ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) </s>
