code
stringlengths
5
1.03M
repo_name
stringlengths
5
90
path
stringlengths
4
158
license
stringclasses
15 values
size
int64
5
1.03M
n_ast_errors
int64
0
53.9k
ast_max_depth
int64
2
4.17k
n_whitespaces
int64
0
365k
n_ast_nodes
int64
3
317k
n_ast_terminals
int64
1
171k
n_ast_nonterminals
int64
1
146k
loc
int64
-1
37.3k
cycloplexity
int64
-1
1.31k
-- | -- Copyright : (c) Sam Truzjan 2013, 2014 -- License : BSD3 -- Maintainer : [email protected] -- Stability : experimental -- Portability : portable -- -- KRPC messages types used in communication. All messages are -- encoded as bencode dictionary. -- -- Normally, you don't need to import this module. -- -- See <http://www.bittorrent.org/beps/bep_0005.html#krpc-protocol> -- {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE TypeSynonymInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE DeriveDataTypeable #-} module Network.KRPC.Message ( -- * Transaction TransactionId -- * Error , ErrorCode (..) , KError(..) , decodeError , unknownMessage -- * Query , KQuery(..) , MethodName -- * Response , KResponse(..) -- * Message , KMessage (..) ) where import Control.Applicative import Control.Exception.Lifted as Lifted import Data.BEncode as BE import Data.ByteString as B import Data.ByteString.Char8 as BC import Data.Typeable -- | This transaction ID is generated by the querying node and is -- echoed in the response, so responses may be correlated with -- multiple queries to the same node. The transaction ID should be -- encoded as a short string of binary numbers, typically 2 characters -- are enough as they cover 2^16 outstanding queries. type TransactionId = ByteString unknownTransaction :: TransactionId unknownTransaction = "" {----------------------------------------------------------------------- -- Error messages -----------------------------------------------------------------------} -- | Types of RPC errors. data ErrorCode -- | Some error doesn't fit in any other category. = GenericError -- | Occur when server fail to process procedure call. | ServerError -- | Malformed packet, invalid arguments or bad token. | ProtocolError -- | Occur when client trying to call method server don't know. | MethodUnknown deriving (Show, Read, Eq, Ord, Bounded, Typeable) -- | According to the table: -- <http://bittorrent.org/beps/bep_0005.html#errors> instance Enum ErrorCode where fromEnum GenericError = 201 fromEnum ServerError = 202 fromEnum ProtocolError = 203 fromEnum MethodUnknown = 204 {-# INLINE fromEnum #-} toEnum 201 = GenericError toEnum 202 = ServerError toEnum 203 = ProtocolError toEnum 204 = MethodUnknown toEnum _ = GenericError {-# INLINE toEnum #-} instance BEncode ErrorCode where toBEncode = toBEncode . fromEnum {-# INLINE toBEncode #-} fromBEncode b = toEnum <$> fromBEncode b {-# INLINE fromBEncode #-} -- | Errors are sent when a query cannot be fulfilled. Error message -- can be send only from server to client but not in the opposite -- direction. -- data KError = KError { errorCode :: !ErrorCode -- ^ the type of error; , errorMessage :: !ByteString -- ^ human-readable text message; , errorId :: !TransactionId -- ^ match to the corresponding 'queryId'. } deriving (Show, Read, Eq, Ord, Typeable) -- | Errors, or KRPC message dictionaries with a \"y\" value of \"e\", -- contain one additional key \"e\". The value of \"e\" is a -- list. The first element is an integer representing the error -- code. The second element is a string containing the error -- message. -- -- Example Error Packet: -- -- > { "t": "aa", "y":"e", "e":[201, "A Generic Error Ocurred"]} -- -- or bencoded: -- -- > d1:eli201e23:A Generic Error Ocurrede1:t2:aa1:y1:ee -- instance BEncode KError where toBEncode KError {..} = toDict $ "e" .=! (errorCode, errorMessage) .: "t" .=! errorId .: "y" .=! ("e" :: ByteString) .: endDict {-# INLINE toBEncode #-} fromBEncode = fromDict $ do lookAhead $ match "y" (BString "e") (code, msg) <- field (req "e") KError code msg <$>! "t" {-# INLINE fromBEncode #-} instance Exception KError -- | Received 'queryArgs' or 'respVals' can not be decoded. decodeError :: String -> TransactionId -> KError decodeError msg = KError ProtocolError (BC.pack msg) -- | A remote node has send some 'KMessage' this node is unable to -- decode. unknownMessage :: String -> KError unknownMessage msg = KError ProtocolError (BC.pack msg) unknownTransaction {----------------------------------------------------------------------- -- Query messages -----------------------------------------------------------------------} type MethodName = ByteString -- | Query used to signal that caller want to make procedure call to -- callee and pass arguments in. Therefore query may be only sent from -- client to server but not in the opposite direction. -- data KQuery = KQuery { queryArgs :: !BValue -- ^ values to be passed to method; , queryMethod :: !MethodName -- ^ method to call; , queryId :: !TransactionId -- ^ one-time query token. } deriving (Show, Read, Eq, Ord, Typeable) -- | Queries, or KRPC message dictionaries with a \"y\" value of -- \"q\", contain two additional keys; \"q\" and \"a\". Key \"q\" has -- a string value containing the method name of the query. Key \"a\" -- has a dictionary value containing named arguments to the query. -- -- Example Query packet: -- -- > { "t" : "aa", "y" : "q", "q" : "ping", "a" : { "msg" : "hi!" } } -- instance BEncode KQuery where toBEncode KQuery {..} = toDict $ "a" .=! queryArgs .: "q" .=! queryMethod .: "t" .=! queryId .: "y" .=! ("q" :: ByteString) .: endDict {-# INLINE toBEncode #-} fromBEncode = fromDict $ do lookAhead $ match "y" (BString "q") KQuery <$>! "a" <*>! "q" <*>! "t" {-# INLINE fromBEncode #-} {----------------------------------------------------------------------- -- Response messages -----------------------------------------------------------------------} -- | Response messages are sent upon successful completion of a -- query: -- -- * KResponse used to signal that callee successufully process a -- procedure call and to return values from procedure. -- -- * KResponse should not be sent if error occurred during RPC, -- 'KError' should be sent instead. -- -- * KResponse can be only sent from server to client. -- data KResponse = KResponse { respVals :: BValue -- ^ 'BDict' containing return values; , respId :: TransactionId -- ^ match to the corresponding 'queryId'. } deriving (Show, Read, Eq, Ord, Typeable) -- | Responses, or KRPC message dictionaries with a \"y\" value of -- \"r\", contain one additional key \"r\". The value of \"r\" is a -- dictionary containing named return values. -- -- Example Response packet: -- -- > { "t" : "aa", "y" : "r", "r" : { "msg" : "you've sent: hi!" } } -- instance BEncode KResponse where toBEncode KResponse {..} = toDict $ "r" .=! respVals .: "t" .=! respId .: "y" .=! ("r" :: ByteString) .: endDict {-# INLINE toBEncode #-} fromBEncode = fromDict $ do lookAhead $ match "y" (BString "r") KResponse <$>! "r" <*>! "t" {-# INLINE fromBEncode #-} {----------------------------------------------------------------------- -- Summed messages -----------------------------------------------------------------------} -- | Generic KRPC message. data KMessage = Q KQuery | R KResponse | E KError deriving (Show, Eq) instance BEncode KMessage where toBEncode (Q q) = toBEncode q toBEncode (R r) = toBEncode r toBEncode (E e) = toBEncode e fromBEncode b = Q <$> fromBEncode b <|> R <$> fromBEncode b <|> E <$> fromBEncode b <|> decodingError "KMessage: unknown message or message tag"
pxqr/krpc
src/Network/KRPC/Message.hs
bsd-3-clause
7,791
0
14
1,645
1,066
621
445
-1
-1
{-# LANGUAGE QuasiQuotes #-} module VirtualMethodsWithNoOverride (testVirtualMethodsWithNoOverride) where import Pygmalion.Test import Pygmalion.Test.TH testVirtualMethodsWithNoOverride = runPygmalionTest "virtual-no-override.cpp" $ [pygTest| #include "virtual.h" int main(int argc, char** argv) { // Classes which don't override a virtual method defined in an ancestor class. ABD ABD_instance; ABD_instance.@A_pure_method(); ~[Def "AB::A_pure_method() [CXXMethod]"]~ ABD_instance.@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABD_instance.AB::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABD_instance.ABD::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABD* ABD_ptr; ABD_ptr->@A_pure_method(); ~~ ~[Defs ["AB::A_pure_method() [CXXMethod]", "ABDE::A_pure_method() [CXXMethod]", "ABDEF::A_pure_method() [CXXMethod]"]]~ ABD_ptr->@AB_method(0); ~~ ~[Defs ["AB::AB_method(int) [CXXMethod]", "ABDE::AB_method(int) [CXXMethod]", "ABDEF::AB_method(int) [CXXMethod]"]]~ ABD_ptr->AB::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABD_ptr->ABD::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABD& ABD_ref = ABD_instance; ABD_ref.@A_pure_method(); ~~ ~[Defs ["AB::A_pure_method() [CXXMethod]", "ABDE::A_pure_method() [CXXMethod]", "ABDEF::A_pure_method() [CXXMethod]"]]~ ABD_ref.@AB_method(0); ~~ ~[Defs ["AB::AB_method(int) [CXXMethod]", "ABDE::AB_method(int) [CXXMethod]", "ABDEF::AB_method(int) [CXXMethod]"]]~ ABD_ref.AB::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABD_ref.ABD::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ // Classes which have an ancestor which didn't override a method. ABDE ABDE_instance; ABDE_instance.@A_pure_method(); ~[Def "ABDE::A_pure_method() [CXXMethod]"]~ ABDE_instance.@AB_method(0); ~[Def "ABDE::AB_method(int) [CXXMethod]"]~ ABDE_instance.AB::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABDE_instance.ABD::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABDE_instance.ABDE::@AB_method(0); ~[Def "ABDE::AB_method(int) [CXXMethod]"]~ ABDE* ABDE_ptr; ABDE_ptr->@A_pure_method(); ~~ ~[Defs ["ABDE::A_pure_method() [CXXMethod]", "ABDEF::A_pure_method() [CXXMethod]"]]~ ABDE_ptr->@AB_method(0); ~~ ~[Defs ["ABDE::AB_method(int) [CXXMethod]", "ABDEF::AB_method(int) [CXXMethod]"]]~ ABDE_ptr->AB::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABDE_ptr->ABD::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABDE_ptr->ABDE::@AB_method(0); ~[Def "ABDE::AB_method(int) [CXXMethod]"]~ ABDE& ABDE_ref = ABDE_instance; ABDE_ref.@A_pure_method(); ~~ ~[Defs ["ABDE::A_pure_method() [CXXMethod]", "ABDEF::A_pure_method() [CXXMethod]"]]~ ABDE_ref.@AB_method(0); ~~ ~[Defs ["ABDE::AB_method(int) [CXXMethod]", "ABDEF::AB_method(int) [CXXMethod]"]]~ ABDE_ref.AB::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABDE_ref.ABD::@AB_method(0); ~[Def "AB::AB_method(int) [CXXMethod]"]~ ABDE_ref.ABDE::@AB_method(0); ~[Def "ABDE::AB_method(int) [CXXMethod]"]~ return 0; } |]
sethfowler/pygmalion
tests/VirtualMethodsWithNoOverride.hs
bsd-3-clause
3,512
0
6
730
37
24
13
5
1
{-# LANGUAGE OverloadedStrings, GeneralizedNewtypeDeriving, ScopedTypeVariables, FlexibleInstances, DeriveDataTypeable, UndecidableInstances, BangPatterns, OverlappingInstances, DataKinds, GADTs, KindSignatures, NamedFieldPuns #-} -- | Haskell client for Cassandra's CQL protocol -- -- For examples, take a look at the /tests/ directory in the source archive. -- -- Here's the correspondence between CQL and Haskell types: -- -- * ascii - 'Ascii' (newtype of 'ByteString') -- -- * bigint - 'Int64' -- -- * blob - 'ByteString' -- -- * boolean - 'Bool' -- -- * counter - 'Counter' -- -- * decimal - 'Decimal' -- -- * double - 'Double' -- -- * float - 'Float' -- -- * int - 'Int' -- -- * text / varchar - 'Text' -- -- * timestamp - 'UTCTime' -- -- * uuid - 'UUID' -- -- * varint - 'Integer' -- -- * timeuuid - 'TimeUUID' -- -- * inet - 'SockAddr' -- -- * list\<a\> - [a] -- -- * map\<a, b\> - 'Map' a b -- -- * set\<a\> - 'Set' b -- -- * tuple<a,b> - '(a,b) -- -- * UDT -- -- ...and you can define your own 'CasType' instances to extend these types, which is -- a very powerful way to write your code. -- -- One way to do things is to specify your queries with a type signature, like this: -- -- > createSongs :: Query Schema () () -- > createSongs = "create table songs (id uuid PRIMARY KEY, title text, artist text, comment text)" -- > -- > insertSong :: Query Write (UUID, Text, Text, Maybe Text) () -- > insertSong = "insert into songs (id, title, artist, comment) values (?, ?, ?)" -- > -- > getOneSong :: Query Rows UUID (Text, Text, Maybe Text) -- > getOneSong = "select title, artist, comment from songs where id=?" -- -- The three type parameters are the query type ('Schema', 'Write' or 'Rows') followed by the -- input and output types, which are given as tuples whose constituent types must match -- the ones in the query CQL. If you do not match them correctly, you'll get a runtime -- error when you execute the query. If you do, then the query becomes completely type -- safe. -- -- Types can be 'Maybe' types, in which case you can read and write a Cassandra \'null\' -- in the table. Cassandra allows any column to be null, but you can lock this out by -- specifying non-Maybe types. -- -- The query types are: -- -- * 'Schema' for modifications to the schema. The output tuple type must be (). -- -- * 'Write' for row inserts and updates, and such. The output tuple type must be (). -- -- * 'Rows' for selects that give a list of rows in response. -- -- The functions to use for these query types are 'executeSchema', -- 'executeWrite', 'executeTrans' and 'executeRows' or 'executeRow' -- respectively. -- -- The following pattern seems to work very well, especially along with your own 'CasType' -- instances, because it gives you a place to neatly add marshalling details that keeps -- away from the body of your code. -- -- > insertSong :: UUID -> Text -> Text -> Maybe Text -> Cas () -- > insertSong id title artist comment = executeWrite QUORUM q (id, title, artist, comment) -- > where q = "insert into songs (id, title, artist, comment) values (?, ?, ?, ?)" -- -- Incidentally, here's Haskell's little-known multi-line string syntax. -- You escape it using \\ and then another \\ where the string starts again. -- -- > str = "multi\ -- > \line" -- -- (gives \"multiline\") -- -- /To do/ -- -- * Add the ability to easily run queries in parallel. -- * Add support for batch queries. -- * Add support for query paging. module Database.Cassandra.CQL ( -- * Initialization Server, Keyspace(..), Pool, newPool, newPool', defaultConfig, -- * Cassandra monad MonadCassandra(..), Cas, runCas, CassandraException(..), CassandraCommsError(..), TransportDirection(..), -- * Auth Authentication (..), -- * Queries Query, Style(..), query, -- * Executing queries Consistency(..), Change(..), executeSchema, executeSchemaVoid, executeWrite, executeRows, executeRow, executeTrans, -- * Value types Ascii(..), Counter(..), TimeUUID(..), metadataTypes, CasType(..), CasValues(..), -- * Lower-level interfaces executeRaw, Result(..), TableSpec(..), ColumnSpec(..), Metadata(..), CType(..), Table(..), PreparedQueryID(..), serverStats, ServerStat(..), PoolConfig(..), -- * Misc for UDTs getOption, putOption, getString, putString ) where import Control.Applicative import Control.Concurrent (threadDelay, forkIO) import Control.Concurrent.STM import Control.Exception (IOException, SomeException, MaskingState(..), throwIO, getMaskingState) import Control.Monad.Catch import Control.Monad.Reader import Control.Monad.State hiding (get, put) import qualified Control.Monad.RWS import qualified Control.Monad.Error import qualified Control.Monad.Writer import Crypto.Hash (hash, Digest, SHA1) import Data.Bits import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as C8BS import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as L import Data.Data import Data.Decimal import Data.Either (lefts) import Data.Int import Data.List import Data.Map (Map) import qualified Data.Map as M import Data.Maybe import qualified Data.Foldable as F import Data.Monoid (Monoid) import qualified Data.Sequence as Seq import Data.Serialize hiding (Result) import Data.Set (Set) import qualified Data.Set as S import qualified Data.Pool as P import Data.String import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Encoding as T import Data.Time.Calendar import Data.Time.Clock import Data.Typeable () import Data.UUID (UUID) import qualified Data.UUID as UUID import Data.Word import Network.Socket (Socket, HostName, ServiceName, getAddrInfo, socket, AddrInfo(..), connect, sClose, SockAddr(..), SocketType(..), defaultHints) import Network.Socket.ByteString (sendAll, recv) import Numeric import Unsafe.Coerce import Data.Function (on) import Data.Monoid ((<>)) import Data.Fixed (Pico) import System.Timeout (timeout) import System.Log.Logger (debugM, warningM) import Debug.Trace defaultConnectionTimeout :: NominalDiffTime defaultConnectionTimeout = 10 defaultIoTimeout :: NominalDiffTime defaultIoTimeout = 300 defaultSessionCreateTimeout :: NominalDiffTime defaultSessionCreateTimeout = 20 defaultBackoffOnError :: NominalDiffTime defaultBackoffOnError = 60 defaultMaxSessionIdleTime :: NominalDiffTime defaultMaxSessionIdleTime = 60 defaultMaxSessions :: Int defaultMaxSessions = 20 type Server = (HostName, ServiceName) data ActiveSession = ActiveSession { actServer :: Server, actSocket :: Socket, actIoTimeout :: NominalDiffTime, actQueryCache :: Map QueryID PreparedQuery } data Session = Session { sessServerIndex :: Int, sessServer :: Server, sessSocket :: Socket } data ServerState = ServerState { ssServer :: Server, ssOrdinal :: Int, ssSessionCount :: Int, ssLastError :: Maybe UTCTime, ssAvailable :: Bool } deriving (Show, Eq) instance Ord ServerState where compare = let compareCount = compare `on` ssSessionCount tieBreaker = compare `on` ssOrdinal in compareCount <> tieBreaker data PoolConfig = PoolConfig { piServers :: [Server], piKeyspace :: Keyspace, piKeyspaceConfig :: Maybe Text, piAuth :: Maybe Authentication, piSessionCreateTimeout :: NominalDiffTime, piConnectionTimeout :: NominalDiffTime, piIoTimeout :: NominalDiffTime, piBackoffOnError :: NominalDiffTime, piMaxSessionIdleTime :: NominalDiffTime, piMaxSessions :: Int } data PoolState = PoolState { psConfig :: PoolConfig, psServers :: TVar (Seq.Seq ServerState) } -- | Exported stats for a server. data ServerStat = ServerStat { statServer :: Server, statSessionCount :: Int, statAvailable :: Bool } deriving (Show) newtype Pool = Pool (PoolState, P.Pool Session) class MonadCatch m => MonadCassandra m where getCassandraPool :: m Pool instance MonadCassandra m => MonadCassandra (Control.Monad.Reader.ReaderT a m) where getCassandraPool = lift getCassandraPool instance MonadCassandra m => MonadCassandra (Control.Monad.State.StateT a m) where getCassandraPool = lift getCassandraPool instance (MonadCassandra m, Control.Monad.Error.Error e) => MonadCassandra (Control.Monad.Error.ErrorT e m) where getCassandraPool = lift getCassandraPool instance (MonadCassandra m, Monoid a) => MonadCassandra (Control.Monad.Writer.WriterT a m) where getCassandraPool = lift getCassandraPool instance (MonadCassandra m, Monoid w) => MonadCassandra (Control.Monad.RWS.RWST r w s m) where getCassandraPool = lift getCassandraPool defaultConfig :: [Server] -> Keyspace -> Maybe Authentication -> PoolConfig defaultConfig servers keyspace auth = PoolConfig { piServers = servers, piKeyspace = keyspace, piKeyspaceConfig = Nothing, piAuth = auth, piSessionCreateTimeout = defaultSessionCreateTimeout, piConnectionTimeout = defaultConnectionTimeout, piIoTimeout = defaultIoTimeout, piBackoffOnError = defaultBackoffOnError, piMaxSessionIdleTime = defaultMaxSessionIdleTime, piMaxSessions = defaultMaxSessions } -- | Construct a pool of Cassandra connections. newPool :: [Server] -> Keyspace -> Maybe Authentication -> IO Pool newPool servers keyspace auth = newPool' $ defaultConfig servers keyspace auth newPool' :: PoolConfig -> IO Pool newPool' config@PoolConfig { piServers, piMaxSessions, piMaxSessionIdleTime } = do when (null piServers) $ throwIO $ userError "at least one server required" -- TODO: Shuffle ordinals let servers = Seq.fromList $ map (\(s, idx) -> ServerState s idx 0 Nothing True) $ zip piServers [0..] servers' <- atomically $ newTVar servers let poolState = PoolState { psConfig = config, psServers = servers' } sessions <- P.createPool (newSession poolState) (destroySession poolState) 1 piMaxSessionIdleTime piMaxSessions let pool = Pool (poolState, sessions) _ <- forkIO $ poolWatch pool return pool poolWatch :: Pool -> IO () poolWatch (Pool (PoolState { psConfig, psServers }, _)) = do let loop = do cutoff <- (piBackoffOnError psConfig `addUTCTime`) <$> getCurrentTime debugM "Database.Cassandra.CQL.poolWatch" "starting" sleepTil <- atomically $ do servers <- readTVar psServers let availableAgain = filter (((&&) <$> (not . ssAvailable) <*> (maybe False (<= cutoff) . ssLastError)) . snd) (zip [0..] $ F.toList servers) servers' = F.foldr' (\(idx, server) accum -> Seq.update idx server { ssAvailable = True } accum) servers availableAgain nextWakeup = F.foldr' (\s nwu -> if not (ssAvailable s) && maybe False (<= nwu) (ssLastError s) then fromJust . ssLastError $ s else nwu) cutoff servers' writeTVar psServers servers' return nextWakeup delay <- (sleepTil `diffUTCTime`) <$> getCurrentTime statusDump <- atomically $ readTVar psServers debugM "Database.Cassandra.CQL.poolWatch" $ "completed : delaying for " ++ show delay ++ ", server states : " ++ show statusDump threadDelay (floor $ delay * 1000000) loop loop serverStats :: Pool -> IO [ServerStat] serverStats (Pool (PoolState { psServers }, _)) = atomically $ do servers <- readTVar psServers return $ map (\ServerState { ssServer, ssSessionCount, ssAvailable } -> ServerStat { statServer = ssServer, statSessionCount = ssSessionCount, statAvailable = ssAvailable }) (F.toList servers) newSession :: PoolState -> IO Session newSession poolState@PoolState { psConfig, psServers } = do debugM "Database.Cassandra.CQL.nextSession" "starting" maskingState <- getMaskingState when (maskingState == Unmasked) $ throwIO $ userError "caller MUST mask async exceptions before attempting to create a session" startTime <- getCurrentTime let giveUpAt = piSessionCreateTimeout psConfig `addUTCTime` startTime loop = do timeLeft <- (giveUpAt `diffUTCTime`) <$> getCurrentTime when (timeLeft <= 0) $ throwIO NoAvailableServers debugM "Database.Cassandra.CQL.newSession" "starting attempt to create a new session" sessionZ <- timeout ((floor $ timeLeft * 1000000) :: Int) makeSession `catches` [ Handler $ (\(e :: CassandraCommsError) -> do warningM "Database.Cassandra.CQL.newSession" $ "failed to create a session due to temporary error (will retry) : " ++ show e return Nothing), Handler $ (\(e :: SomeException) -> do warningM "Database.Cassandra.CQL.newSession" $ "failed to create a session due to permanent error (will rethrow) : " ++ show e throwIO e) ] case sessionZ of Just session -> return session Nothing -> loop makeSession = bracketOnError chooseServer restoreCount setup chooseServer = atomically $ do servers <- readTVar psServers let available = filter (ssAvailable . snd) (zip [0..] $ F.toList servers) if null available then retry else do let (idx, best @ ServerState { ssSessionCount }) = minimumBy (compare `on` snd) available updatedBest = best { ssSessionCount = ssSessionCount + 1 } modifyTVar' psServers (Seq.update idx updatedBest) return (updatedBest, idx) restoreCount (_, idx) = do now <- getCurrentTime atomically $ modifyTVar' psServers (Seq.adjust (\s -> s { ssSessionCount = ssSessionCount s - 1, ssLastError = Just now, ssAvailable = False }) idx) setup (ServerState { ssServer }, idx) = setupConnection poolState idx ssServer loop destroySession :: PoolState -> Session -> IO () destroySession PoolState { psServers } Session { sessSocket, sessServerIndex } = mask $ \restore -> do atomically $ modifyTVar' psServers (Seq.adjust (\s -> s { ssSessionCount = ssSessionCount s - 1 }) sessServerIndex) restore (sClose sessSocket) setupConnection :: PoolState -> Int -> Server -> IO Session setupConnection PoolState { psConfig } serverIndex server = do let hints = defaultHints { addrSocketType = Stream } (host, service) = server debugM "Database.Cassandra.CQL.setupConnection" $ "attempting to connect to " ++ host startTime <- getCurrentTime ais <- getAddrInfo (Just hints) (Just host) (Just service) bracketOnError (connectSocket startTime ais) (maybe (return ()) sClose) buildSession where connectSocket startTime ais = foldM (\mSocket ai -> do case mSocket of Nothing -> do let tryConnect = do debugM "Database.Cassandra.CQL.setupConnection" $ "trying address " ++ show ai -- No need to use 'bracketOnError' here because we are already masked. s <- socket (addrFamily ai) (addrSocketType ai) (addrProtocol ai) mConn <- timeout ((floor $ (piConnectionTimeout psConfig) * 1000000) :: Int) (connect s (addrAddress ai)) `onException` sClose s case mConn of Nothing -> sClose s >> return Nothing Just _ -> return $ Just s now <- getCurrentTime if now `diffUTCTime` startTime >= piConnectionTimeout psConfig then return Nothing else tryConnect `catch` (\ (e :: SomeException) -> do debugM "Database.Cassandra.CQL.setupConnection" $ "failed to connect to address " ++ show ai ++ " : " ++ show e return Nothing ) Just _ -> return mSocket ) Nothing ais buildSession (Just s) = do debugM "Database.Cassandra.CQL.setupConnection" $ "made connection, now attempting setup for socket " ++ show s let active = Session { sessServerIndex = serverIndex, sessServer = server, sessSocket = s } evalStateT (introduce psConfig) (activeSession psConfig active) return active buildSession Nothing = throwIO NoAvailableServers data Flag = Compression | Tracing deriving Show putFlags :: [Flag] -> Put putFlags flags = putWord8 $ foldl' (+) 0 $ map toWord8 flags where toWord8 Compression = 0x01 toWord8 Tracing = 0x02 getFlags :: Get [Flag] getFlags = do flagsB <- getWord8 return $ case flagsB .&. 3 of 0 -> [] 1 -> [Compression] 2 -> [Tracing] 3 -> [Compression, Tracing] _ -> error "recvFrame impossible" data Opcode = ERROR | STARTUP | READY | AUTHENTICATE | OPTIONS | SUPPORTED | QUERY | RESULT | PREPARE | EXECUTE | REGISTER | EVENT | BATCH | AUTH_CHALLENGE | AUTH_RESPONSE | AUTH_SUCCESS deriving (Eq, Show) instance Serialize Opcode where put op = putWord8 $ case op of ERROR -> 0x00 STARTUP -> 0x01 READY -> 0x02 AUTHENTICATE -> 0x03 OPTIONS -> 0x05 SUPPORTED -> 0x06 QUERY -> 0x07 RESULT -> 0x08 PREPARE -> 0x09 EXECUTE -> 0x0a REGISTER -> 0x0b EVENT -> 0x0c BATCH -> 0x0d AUTH_CHALLENGE -> 0x0e AUTH_RESPONSE -> 0x0f AUTH_SUCCESS -> 0x10 get = do w <- getWord8 case w of 0x00 -> return ERROR 0x01 -> return STARTUP 0x02 -> return READY 0x03 -> return AUTHENTICATE 0x05 -> return OPTIONS 0x06 -> return SUPPORTED 0x07 -> return QUERY 0x08 -> return RESULT 0x09 -> return PREPARE 0x0a -> return EXECUTE 0x0b -> return REGISTER 0x0c -> return EVENT 0x0d -> return BATCH 0x0e -> return AUTH_CHALLENGE 0x0f -> return AUTH_RESPONSE 0x10 -> return AUTH_SUCCESS _ -> fail $ "unknown opcode 0x"++showHex w "" data Frame a = Frame { _frFlags :: [Flag], _frStream :: Int16, frOpcode :: Opcode, frBody :: a } deriving Show timeout' :: NominalDiffTime -> IO a -> IO a timeout' to = timeout (floor $ to * 1000000) >=> maybe (throwIO CoordinatorTimeout) return recvAll :: NominalDiffTime -> Socket -> Int -> IO ByteString recvAll ioTimeout s n = timeout' ioTimeout $ do bs <- recv s n when (B.null bs) $ throwM ShortRead let left = n - B.length bs if left == 0 then return bs else do bs' <- recvAll ioTimeout s left return (bs `B.append` bs') protocolVersion :: Word8 protocolVersion = 3 recvFrame :: Text -> StateT ActiveSession IO (Frame ByteString) recvFrame qt = do s <- gets actSocket ioTimeout <- gets actIoTimeout hdrBs <- liftIO $ recvAll ioTimeout s 9 case runGet parseHeader hdrBs of Left err -> throwM $ LocalProtocolError ("recvFrame: " `T.append` T.pack err) qt Right (ver0, flags, stream, opcode, length) -> do let ver = ver0 .&. 0x7f when (ver /= protocolVersion) $ throwM $ LocalProtocolError ("unexpected version " `T.append` T.pack (show ver)) qt body <- if length == 0 then pure B.empty else liftIO $ recvAll ioTimeout s (fromIntegral length) --liftIO $ putStrLn $ hexdump 0 (C.unpack $ hdrBs `B.append` body) return $ Frame flags stream opcode body `catch` \exc -> throwM $ CassandraIOException exc where parseHeader = do ver <- getWord8 flags <- getFlags stream <- fromIntegral <$> getWord16be opcode <- get length <- getWord32be return (ver, flags, stream, opcode, length) sendFrame :: Frame ByteString -> StateT ActiveSession IO () sendFrame (Frame flags stream opcode body) = do let bs = runPut $ do putWord8 protocolVersion putFlags flags putWord16be (fromIntegral stream) put opcode putWord32be $ fromIntegral $ B.length body putByteString body --liftIO $ putStrLn $ hexdump 0 (C.unpack bs) s <- gets actSocket ioTimeout <- gets actIoTimeout liftIO $ timeout' ioTimeout $ sendAll s bs `catch` \exc -> throwM $ CassandraIOException exc class ProtoElt a where getElt :: Get a putElt :: a -> Put encodeElt :: ProtoElt a => a -> ByteString encodeElt = runPut . putElt encodeCas :: CasType a => a -> ByteString encodeCas = runPut . putCas decodeElt :: ProtoElt a => ByteString -> Either String a decodeElt bs = runGet getElt bs decodeCas :: CasType a => ByteString -> Either String a decodeCas bs = runGet getCas bs decodeEltM :: (ProtoElt a, MonadIO m, MonadThrow m) => Text -> ByteString -> Text -> m a decodeEltM what bs qt = case decodeElt bs of Left err -> throwM $ LocalProtocolError ("can't parse" `T.append` what `T.append` ": " `T.append` T.pack err) qt Right res -> return res newtype Long a = Long { unLong :: a } deriving (Eq, Ord, Show, Read) instance Functor Long where f `fmap` Long a = Long (f a) newtype Short a = Short { unShort :: a } deriving (Eq, Ord, Show, Read) instance Functor Short where f `fmap` Short a = Short (f a) instance ProtoElt (Map Text Text) where putElt = putElt . M.assocs getElt = M.fromList <$> getElt instance ProtoElt [(Text, Text)] where putElt pairs = do putWord16be (fromIntegral $ length pairs) forM_ pairs $ \(key, value) -> do putElt key putElt value getElt = do n <- getWord16be replicateM (fromIntegral n) $ do key <- getElt value <- getElt return (key, value) instance ProtoElt Text where putElt = putElt . T.encodeUtf8 getElt = T.decodeUtf8 <$> getElt instance ProtoElt (Long Text) where putElt = putElt . fmap T.encodeUtf8 getElt = fmap T.decodeUtf8 <$> getElt instance ProtoElt ByteString where putElt bs = do putWord16be (fromIntegral $ B.length bs) putByteString bs getElt = do len <- getWord16be getByteString (fromIntegral len) instance ProtoElt (Long ByteString) where putElt (Long bs) = do putWord32be (fromIntegral $ B.length bs) putByteString bs getElt = do len <- getWord32be Long <$> getByteString (fromIntegral len) data TransportDirection = TransportSending | TransportReceiving deriving (Eq, Show) -- | An exception that indicates an error originating in the Cassandra server. data CassandraException = ServerError Text Text | ProtocolError Text Text | BadCredentials Text Text | UnavailableException Text Consistency Int Int Text | Overloaded Text Text | IsBootstrapping Text Text | TruncateError Text Text | WriteTimeout Text Consistency Int Int Text Text | ReadTimeout Text Consistency Int Int Bool Text | SyntaxError Text Text | Unauthorized Text Text | Invalid Text Text | ConfigError Text Text | AlreadyExists Text Keyspace Table Text | Unprepared Text PreparedQueryID Text deriving (Show, Typeable) instance Exception CassandraException where -- | All errors at the communications level are reported with this exception -- ('IOException's from socket I/O are always wrapped), and this exception -- typically would mean that a retry is warranted. -- -- Note that this exception isn't guaranteed to be a transient one, so a limit -- on the number of retries is likely to be a good idea. -- 'LocalProtocolError' probably indicates a corrupted database or driver -- bug. data CassandraCommsError = AuthenticationException Text | LocalProtocolError Text Text | MissingAuthenticationError Text Text | ValueMarshallingException TransportDirection Text Text | CassandraIOException IOException | CreateKeyspaceError Text Text | ShortRead | NoAvailableServers | CoordinatorTimeout deriving (Show, Typeable) instance Exception CassandraCommsError throwError :: MonadCatch m => Text -> ByteString -> m a throwError qt bs = do case runGet parseError bs of Left err -> throwM $ LocalProtocolError ("failed to parse error: " `T.append` T.pack err) qt Right exc -> throwM exc where parseError :: Get CassandraException parseError = do code <- getWord32be case code of 0x0000 -> ServerError <$> getElt <*> pure qt 0x000A -> ProtocolError <$> getElt <*> pure qt 0x0100 -> BadCredentials <$> getElt <*> pure qt 0x1000 -> UnavailableException <$> getElt <*> getElt <*> (fromIntegral <$> getWord32be) <*> (fromIntegral <$> getWord32be) <*> pure qt 0x1001 -> Overloaded <$> getElt <*> pure qt 0x1002 -> IsBootstrapping <$> getElt <*> pure qt 0x1003 -> TruncateError <$> getElt <*> pure qt 0x1100 -> WriteTimeout <$> getElt <*> getElt <*> (fromIntegral <$> getWord32be) <*> (fromIntegral <$> getWord32be) <*> getElt <*> pure qt 0x1200 -> ReadTimeout <$> getElt <*> getElt <*> (fromIntegral <$> getWord32be) <*> (fromIntegral <$> getWord32be) <*> ((/=0) <$> getWord8) <*> pure qt 0x2000 -> SyntaxError <$> getElt <*> pure qt 0x2100 -> Unauthorized <$> getElt <*> pure qt 0x2200 -> Invalid <$> getElt <*> pure qt 0x2300 -> ConfigError <$> getElt <*> pure qt 0x2400 -> AlreadyExists <$> getElt <*> getElt <*> getElt <*> pure qt 0x2500 -> Unprepared <$> getElt <*> getElt <*> pure qt _ -> fail $ "unknown error code 0x"++showHex code "" type UserId = String type Password = String data Authentication = PasswordAuthenticator UserId Password type Credentials = Long ByteString authCredentials :: Authentication -> Credentials authCredentials (PasswordAuthenticator user password) = Long $ C8BS.pack $ "\0" ++ user ++ "\0" ++ password authenticate :: Authentication -> StateT ActiveSession IO () authenticate auth = do let qt = "<auth_response>" sendFrame $ Frame [] 0 AUTH_RESPONSE $ encodeElt $ authCredentials auth fr2 <- recvFrame qt case frOpcode fr2 of AUTH_SUCCESS -> return () ERROR -> throwError qt (frBody fr2) op -> throwM $ LocalProtocolError ("introduce: unexpected opcode " `T.append` T.pack (show op)) qt introduce :: PoolConfig -> StateT ActiveSession IO () introduce PoolConfig { piKeyspace, piKeyspaceConfig, piAuth } = do let qt = "<startup>" sendFrame $ Frame [] 0 STARTUP $ encodeElt $ ([("CQL_VERSION", "3.0.0")] :: [(Text, Text)]) fr <- recvFrame qt case frOpcode fr of AUTHENTICATE -> maybe (throwM $ MissingAuthenticationError "introduce: server expects auth but none provided" "<credentials>") authenticate piAuth READY -> return () ERROR -> throwError qt (frBody fr) op -> throwM $ LocalProtocolError ("introduce: unexpected opcode " `T.append` T.pack (show op)) qt let Keyspace ksName = piKeyspace case piKeyspaceConfig of Nothing -> return () Just cfg -> do let q = query $ cfg :: Query Schema () () res <- executeInternal q () QUORUM case res of SchemaChange _ _ _ -> return () _ -> throwM $ CreateKeyspaceError ("introduce: failed to create a keyspace: " `T.append` T.pack (show res)) (queryText q) let q = query $ "USE " `T.append` ksName :: Query Rows () () res <- executeInternal q () ONE case res of SetKeyspace ks -> return () _ -> throwM $ LocalProtocolError ("introduce: expected SetKeyspace, but got " `T.append` T.pack (show res)) (queryText q) -- TODO Should we have to add the MonadIO constraint? withSession :: (MonadCassandra m, MonadIO m) => (Pool -> StateT ActiveSession IO a) -> m a withSession code = do pool@(Pool (PoolState { psConfig }, sessions)) <- getCassandraPool liftIO $ mask $ \restore -> do (session, local') <- P.takeResource sessions a <- restore (evalStateT (code pool) (activeSession psConfig session)) `catches` [ Handler $ \(exc :: CassandraException) -> P.putResource local' session >> throwIO exc, Handler $ \(exc :: SomeException) -> P.destroyResource sessions local' session >> throwIO exc ] P.putResource local' session return a activeSession :: PoolConfig -> Session -> ActiveSession activeSession poolConfig session = ActiveSession { actServer = sessServer session, actSocket = sessSocket session, actIoTimeout = piIoTimeout poolConfig, actQueryCache = M.empty } -- | The name of a Cassandra keyspace. See the Cassandra documentation for more -- information. newtype Keyspace = Keyspace Text deriving (Eq, Ord, Show, IsString, ProtoElt) -- | The name of a Cassandra table (a.k.a. column family). newtype Table = Table Text deriving (Eq, Ord, Show, IsString, ProtoElt) -- | A fully qualified identification of a table that includes the 'Keyspace'. data TableSpec = TableSpec Keyspace Table deriving (Eq, Ord, Show) instance ProtoElt TableSpec where putElt _ = error "formatting TableSpec is not implemented" getElt = TableSpec <$> getElt <*> getElt -- | Information about a table column. data ColumnSpec = ColumnSpec TableSpec Text CType deriving Show -- | The specification of a list of result set columns. data Metadata = Metadata [ColumnSpec] deriving Show -- | Cassandra data types as used in metadata. data CType = CCustom Text | CAscii | CBigint | CBlob | CBoolean | CCounter | CDecimal | CDouble | CFloat | CInt | CText | CTimestamp | CUuid | CVarint | CTimeuuid | CInet | CList CType | CMap CType CType | CSet CType | CMaybe CType | CUDT [CType] | CTuple [CType] deriving (Eq) instance Show CType where show ct = case ct of CCustom name -> T.unpack name CAscii -> "ascii" CBigint -> "bigint" CBlob -> "blob" CBoolean -> "boolean" CCounter -> "counter" CDecimal -> "decimal" CDouble -> "double" CFloat -> "float" CInt -> "int" CText -> "text" CTimestamp -> "timestamp" CUuid -> "uuid" CVarint -> "varint" CTimeuuid -> "timeuuid" CInet -> "inet" CList t -> "list<"++show t++">" CMap t1 t2 -> "map<"++show t1++","++show t2++">" CSet t -> "set<"++show t++">" CMaybe t -> "nullable "++show t CUDT ts -> "udt<" ++ (intercalate "," $ fmap show ts) ++ ">" CTuple ts -> "tuple<" ++ (intercalate "," $ fmap show ts) ++ ">" equivalent :: CType -> CType -> Bool equivalent (CTuple a) (CTuple b) = all (\ (x,y) -> x `equivalent` y) $ zip a b equivalent (CMaybe a) (CMaybe b) = a == b equivalent (CMaybe a) b = a == b equivalent a (CMaybe b) = a == b equivalent a b = a == b -- | A type class for types that can be used in query arguments or column values in -- returned results. -- -- To define your own newtypes for Cassandra data, you only need to define 'getCas', -- 'putCas' and 'casType', like this: -- -- > newtype UserId = UserId UUID deriving (Eq, Show) -- > -- > instance CasType UserId where -- > getCas = UserId <$> getCas -- > putCas (UserId i) = putCas i -- > casType (UserId i) = casType i -- -- The same can be done more simply using the /GeneralizedNewtypeDeriving/ language -- extension, e.g. -- -- > {-# LANGUAGE GeneralizedNewtypeDeriving #-} -- > -- > ... -- > newtype UserId = UserId UUID deriving (Eq, Show, CasType) -- -- If you have a more complex type you want to store as a Cassandra blob, you could -- write an instance like this (assuming it's an instance of the /cereal/ package's -- 'Serialize' class): -- -- > instance CasType User where -- > getCas = decode . unBlob <$> getCas -- > putCas = putCas . Blob . encode -- > casType _ = CBlob class CasType a where getCas :: Get a putCas :: a -> Put -- | For a given Haskell type given as ('undefined' :: a), tell the caller how Cassandra -- represents it. casType :: a -> CType casNothing :: a casNothing = error "casNothing impossible" casObliterate :: a -> ByteString -> Maybe ByteString casObliterate _ bs = Just bs instance CasType a => CasType (Maybe a) where getCas = Just <$> getCas putCas Nothing = return () putCas (Just a) = putCas a casType _ = CMaybe (casType (undefined :: a)) casNothing = Nothing casObliterate (Just a) bs = Just bs casObliterate Nothing _ = Nothing -- | If you wrap this round a 'ByteString', it will be treated as an -- /ascii/ type instead of /blob/ (if it was a plain 'ByteString' -- type). Note that the bytes must indeed be in the range of ASCII. -- This is your responsibility when constructing this newtype. newtype Ascii = Ascii { unAscii :: ByteString } deriving (Eq, Ord, Show) instance CasType Ascii where getCas = Ascii <$> (getByteString =<< remaining) putCas = putByteString . unAscii casType _ = CAscii instance CasType Int64 where getCas = fromIntegral <$> getWord64be putCas = putWord64be . fromIntegral casType _ = CBigint instance CasType ByteString where getCas = getByteString =<< remaining putCas bs = putByteString bs casType _ = CBlob instance CasType Bool where getCas = (/= 0) <$> getWord8 putCas True = putWord8 1 putCas False = putWord8 0 casType _ = CBoolean -- | A Cassandra distributed counter value. newtype Counter = Counter { unCounter :: Int64 } deriving (Eq, Ord, Show, Read) instance CasType Counter where getCas = Counter . fromIntegral <$> getWord64be putCas (Counter c) = putWord64be (fromIntegral c) casType _ = CCounter instance CasType Integer where getCas = do ws <- B.unpack <$> (getByteString =<< remaining) return $ if null ws then 0 else let i = foldl' (\i w -> i `shiftL` 8 + fromIntegral w) 0 ws in if head ws >= 0x80 then i - 1 `shiftL` (length ws * 8) else i putCas i = putByteString . B.pack $ if i < 0 then encodeNeg $ positivize 0x80 i else encodePos i where encodePos :: Integer -> [Word8] encodePos i = reverse $ enc i where enc i | i == 0 = [0] enc i | i < 0x80 = [fromIntegral i] enc i = fromIntegral i : enc (i `shiftR` 8) encodeNeg :: Integer -> [Word8] encodeNeg i = reverse $ enc i where enc i | i == 0 = [] enc i | i < 0x100 = [fromIntegral i] enc i = fromIntegral i : enc (i `shiftR` 8) positivize :: Integer -> Integer -> Integer positivize bits i = case bits + i of i' | i' >= 0 -> i' + bits _ -> positivize (bits `shiftL` 8) i casType _ = CVarint instance CasType Decimal where getCas = Decimal <$> (fromIntegral . min 0xff <$> getWord32be) <*> getCas putCas (Decimal places mantissa) = do putWord32be (fromIntegral places) putCas mantissa casType _ = CDecimal instance CasType Double where getCas = unsafeCoerce <$> getWord64be putCas dbl = putWord64be (unsafeCoerce dbl) casType _ = CDouble instance CasType Float where getCas = unsafeCoerce <$> getWord32be putCas dbl = putWord32be (unsafeCoerce dbl) casType _ = CFloat epoch :: UTCTime epoch = UTCTime (fromGregorian 1970 1 1) 0 instance CasType UTCTime where getCas = do ms <- getWord64be let difft = realToFrac $ (fromIntegral ms :: Pico) / 1000 return $ addUTCTime difft epoch putCas utc = do let seconds = realToFrac $ diffUTCTime utc epoch :: Pico ms = round (seconds * 1000) :: Word64 putWord64be ms casType _ = CTimestamp instance CasType Int where getCas = fromIntegral <$> getWord32be putCas = putWord32be . fromIntegral casType _ = CInt instance CasType Text where getCas = T.decodeUtf8 <$> (getByteString =<< remaining) putCas = putByteString . T.encodeUtf8 casType _ = CText instance CasType UUID where getCas = do mUUID <- UUID.fromByteString . L.fromStrict <$> (getByteString =<< remaining) case mUUID of Just uuid -> return uuid Nothing -> fail "malformed UUID" putCas = putByteString . L.toStrict . UUID.toByteString casType _ = CUuid -- | If you wrap this round a 'UUID' then it is treated as a /timeuuid/ type instead of -- /uuid/ (if it was a plain 'UUID' type). newtype TimeUUID = TimeUUID { unTimeUUID :: UUID } deriving (Eq, Data, Ord, Read, Show, Typeable) instance CasType TimeUUID where getCas = TimeUUID <$> getCas putCas (TimeUUID uuid) = putCas uuid casType _ = CTimeuuid instance CasType SockAddr where getCas = do len <- remaining case len of 4 -> SockAddrInet 0 <$> getWord32le 16 -> do a <- getWord32be b <- getWord32be c <- getWord32be d <- getWord32be return $ SockAddrInet6 0 0 (a,b,c,d) 0 _ -> fail "malformed Inet" putCas sa = do case sa of SockAddrInet _ w -> putWord32le w SockAddrInet6 _ _ (a,b,c,d) _ -> putWord32be a >> putWord32be b >> putWord32be c >> putWord32be d _ -> fail $ "address type not supported in formatting Inet: " ++ show sa casType _ = CInet instance CasType a => CasType [a] where getCas = do n <- getWord32be replicateM (fromIntegral n) $ do len <- getWord32be bs <- getByteString (fromIntegral len) case decodeCas bs of Left err -> fail err Right x -> return x putCas xs = do putWord32be (fromIntegral $ length xs) forM_ xs $ \x -> do let bs = encodeCas x putWord32be (fromIntegral $ B.length bs) putByteString bs casType _ = CList (casType (undefined :: a)) instance (CasType a, Ord a) => CasType (Set a) where getCas = S.fromList <$> getCas putCas = putCas . S.toList casType _ = CSet (casType (undefined :: a)) instance (CasType a, Ord a, CasType b) => CasType (Map a b) where getCas = do n <- getWord32be items <- replicateM (fromIntegral n) $ do len_a <- getWord32be bs_a <- getByteString (fromIntegral len_a) a <- case decodeCas bs_a of Left err -> fail err Right x -> return x len_b <- getWord32be bs_b <- getByteString (fromIntegral len_b) b <- case decodeCas bs_b of Left err -> fail err Right x -> return x return (a,b) return $ M.fromList items putCas m = do let items = M.toList m putWord32be (fromIntegral $ length items) forM_ items $ \(a,b) -> do putOption a putOption b casType _ = CMap (casType (undefined :: a)) (casType (undefined :: b)) getString :: Get Text getString = do len <- getWord16be bs <- getByteString (fromIntegral len) return $ T.decodeUtf8 bs putString :: Text -> Put putString x = do putWord16be (fromIntegral $ B.length val) putByteString val where val = T.encodeUtf8 x getOption :: CasType a => Get a getOption = do len <- getWord32be bs <- getByteString (fromIntegral len) case decodeCas bs of Left err -> fail err Right x -> return x putOption :: CasType a => a -> Put putOption x = do let bs = encodeCas x putWord32be (fromIntegral $ B.length bs) putByteString bs instance (CasType a, CasType b) => CasType (a,b) where getCas = do x <- getOption y <- getOption return (x,y) putCas (x,y) = do putOption x putOption y casType _ = CTuple [casType (undefined :: a), casType (undefined :: b)] instance (CasType a, CasType b, CasType c) => CasType(a,b,c) where getCas = do x <- getOption y <- getOption z <- getOption return (x,y,z) putCas (x,y,z) = do putOption x putOption y putOption z casType _ = CTuple [casType (undefined :: a), casType (undefined :: b), casType (undefined :: c)] instance (CasType a,CasType b, CasType c, CasType d) => CasType(a,b,c,d) where getCas = do w <- getOption x <- getOption y <- getOption z <- getOption return (w,x,y,z) putCas (w,x,y,z) = do putOption w putOption x putOption y putOption z casType _ = CTuple [casType (undefined :: a), casType (undefined :: b), casType (undefined :: c), casType (undefined :: d)] instance (CasType a,CasType b, CasType c, CasType d, CasType e) => CasType(a,b,c,d,e) where getCas = do v <- getOption w <- getOption x <- getOption y <- getOption z <- getOption return (v,w,x,y,z) putCas (v,w,x,y,z) = do putOption v putOption w putOption x putOption y putOption z casType _ = CTuple [casType (undefined :: a), casType (undefined :: b), casType (undefined :: c), casType (undefined :: d), casType (undefined :: e)] instance ProtoElt CType where putElt _ = error "formatting CType is not implemented" getElt = do op <- getWord16be case op of 0x0000 -> CCustom <$> getElt 0x0001 -> pure CAscii 0x0002 -> pure CBigint 0x0003 -> pure CBlob 0x0004 -> pure CBoolean 0x0005 -> pure CCounter 0x0006 -> pure CDecimal 0x0007 -> pure CDouble 0x0008 -> pure CFloat 0x0009 -> pure CInt --0x000a -> pure CVarchar -- Server seems to use CText even when 'varchar' is specified -- i.e. they're interchangeable in the CQL and always -- 'text' in the protocol. 0x000b -> pure CTimestamp 0x000c -> pure CUuid 0x000d -> pure CText 0x000e -> pure CVarint 0x000f -> pure CTimeuuid 0x0010 -> pure CInet 0x0020 -> CList <$> getElt 0x0021 -> CMap <$> getElt <*> getElt 0x0022 -> CSet <$> getElt 0x0030 -> CUDT <$> getEltUdt 0x0031 -> CTuple <$> getElt _ -> fail $ "unknown data type code 0x"++showHex op "" getEltUdt = do _ <- getString _ <- getString n <- getWord16be replicateM (fromIntegral n) $ do _ <- getString getElt instance ProtoElt Metadata where putElt _ = error "formatting Metadata is not implemented" getElt = do flags <- getWord32be colCount <- fromIntegral <$> getWord32be gtSpec <- if (flags .&. 1) /= 0 then Just <$> getElt else pure Nothing cols <- replicateM colCount $ do tSpec <- case gtSpec of Just spec -> pure spec Nothing -> getElt ColumnSpec tSpec <$> getElt <*> getElt return $ Metadata cols instance ProtoElt [CType] where getElt = do n <- getWord16be replicateM (fromIntegral n) getElt putElt x = do putWord16be (fromIntegral $ length x) forM_ x putElt newtype PreparedQueryID = PreparedQueryID ByteString deriving (Eq, Ord, Show, ProtoElt) newtype QueryID = QueryID (Digest SHA1) deriving (Eq, Ord, Show) -- | The first type argument for Query. Tells us what kind of query it is. data Style = Schema -- ^ A query that modifies the schema, such as DROP TABLE or CREATE TABLE | Write -- ^ A query that writes data, such as an INSERT or UPDATE | Rows -- ^ A query that returns a list of rows, such as SELECT -- | The text of a CQL query, along with type parameters to make the query type safe. -- The type arguments are 'Style', followed by input and output column types for the -- query each represented as a tuple. -- -- The /DataKinds/ language extension is required for 'Style'. data Query :: Style -> * -> * -> * where Query :: QueryID -> Text -> Query style i o deriving Show queryText :: Query s i o -> Text queryText (Query _ txt) = txt instance IsString (Query style i o) where fromString = query . T.pack -- | Construct a query. Another way to construct one is as an overloaded string through -- the 'IsString' instance if you turn on the /OverloadedStrings/ language extension, e.g. -- -- > {-# LANGUAGE OverloadedStrings #-} -- > ... -- > -- > getOneSong :: Query Rows UUID (Text, Text, Maybe Text) -- > getOneSong = "select title, artist, comment from songs where id=?" query :: Text -> Query style i o query cql = Query (QueryID . hash . T.encodeUtf8 $ cql) cql data PreparedQuery = PreparedQuery PreparedQueryID Metadata deriving Show data Change = CREATED | UPDATED | DROPPED deriving (Eq, Ord, Show) instance ProtoElt Change where putElt _ = error $ "formatting Change is not implemented" getElt = do str <- getElt :: Get Text case str of "CREATED" -> pure CREATED "UPDATED" -> pure UPDATED "DROPPED" -> pure DROPPED _ -> fail $ "unexpected change string: "++show str -- | A low-level query result used with 'executeRaw'. data Result vs = Void | RowsResult Metadata [vs] | SetKeyspace Text | Prepared PreparedQueryID Metadata | SchemaChange Change Keyspace Table deriving Show instance Functor Result where f `fmap` Void = Void f `fmap` RowsResult meta rows = RowsResult meta (f `fmap` rows) f `fmap` SetKeyspace ks = SetKeyspace ks f `fmap` Prepared pqid meta = Prepared pqid meta f `fmap` SchemaChange ch ks t = SchemaChange ch ks t instance ProtoElt (Result [Maybe ByteString]) where putElt _ = error "formatting RESULT is not implemented" getElt = do kind <- getWord32be case kind of 0x0001 -> pure Void 0x0002 -> do meta@(Metadata colSpecs) <- getElt let colCount = length colSpecs rowCount <- fromIntegral <$> getWord32be rows <- replicateM rowCount $ replicateM colCount $ do len <- getWord32be if len == 0xffffffff then return Nothing else Just <$> getByteString (fromIntegral len) return $ RowsResult meta rows 0x0003 -> SetKeyspace <$> getElt 0x0004 -> Prepared <$> getElt <*> getElt 0x0005 -> SchemaChange <$> getElt <*> getElt <*> getElt _ -> fail $ "bad result kind: 0x"++showHex kind "" prepare :: Query style i o -> StateT ActiveSession IO PreparedQuery prepare (Query qid cql) = do cache <- gets actQueryCache case qid `M.lookup` cache of Just pq -> return pq Nothing -> do sendFrame $ Frame [] 0 PREPARE $ encodeElt (Long cql) fr <- recvFrame cql case frOpcode fr of RESULT -> do res <- decodeEltM "RESULT" (frBody fr) cql case (res :: Result [Maybe ByteString]) of Prepared pqid meta -> do let pq = PreparedQuery pqid meta modify $ \act -> act { actQueryCache = M.insert qid pq (actQueryCache act) } return pq _ -> throwM $ LocalProtocolError ("prepare: unexpected result " `T.append` T.pack (show res)) cql ERROR -> throwError cql (frBody fr) _ -> throwM $ LocalProtocolError ("prepare: unexpected opcode " `T.append` T.pack (show (frOpcode fr))) cql data CodingFailure = Mismatch Int CType CType | WrongNumber Int Int | DecodeFailure Int String | NullValue Int CType instance Show CodingFailure where show (Mismatch i t1 t2) = "at value index "++show (i+1)++", Haskell type specifies "++show t1++", but database metadata says "++show t2 show (WrongNumber i1 i2) = "wrong number of values: Haskell type specifies "++show i1++" but database metadata says "++show i2 show (DecodeFailure i why) = "failed to decode value index "++show (i+1)++": "++why show (NullValue i t) = "at value index "++show (i+1)++" received a null "++show t++" value but Haskell type is not a Maybe" class CasNested v where encodeNested :: Int -> v -> [CType] -> Either CodingFailure [Maybe ByteString] decodeNested :: Int -> [(CType, Maybe ByteString)] -> Either CodingFailure v countNested :: v -> Int instance CasNested () where encodeNested !i () [] = Right [] encodeNested !i () ts = Left $ WrongNumber i (i + length ts) decodeNested !i [] = Right () decodeNested !i vs = Left $ WrongNumber i (i + length vs) countNested _ = 0 instance (CasType a, CasNested rem) => CasNested (a, rem) where encodeNested !i (a, rem) (ta:trem) | ta `equivalent` casType a = case encodeNested (i+1) rem trem of Left err -> Left err Right brem -> Right $ ba : brem where ba = casObliterate a . encodeCas $ a encodeNested !i (a, _) (ta:_) = Left $ Mismatch i (casType a) ta encodeNested !i vs [] = Left $ WrongNumber (i + countNested vs) i decodeNested !i ((ta, mba):rem) | ta `equivalent` casType (undefined :: a) = case (decodeCas <$> mba, casType (undefined :: a), decodeNested (i+1) rem) of (Nothing, CMaybe _, Right arem) -> Right (casNothing, arem) (Nothing, _, _) -> Left $ NullValue i ta (Just (Left err), _, _) -> Left $ DecodeFailure i err (_, _, Left err) -> Left err (Just (Right a), _, Right arem) -> Right (a, arem) decodeNested !i ((ta, _):rem) = Left $ Mismatch i (casType (undefined :: a)) ta decodeNested !i [] = Left $ WrongNumber (i + 1 + countNested (undefined :: rem)) i countNested _ = let n = 1 + countNested (undefined :: rem) in seq n n -- | A type class for a tuple of 'CasType' instances, representing either a list of -- arguments for a query, or the values in a row of returned query results. class CasValues v where encodeValues :: v -> [CType] -> Either CodingFailure [Maybe ByteString] decodeValues :: [(CType, Maybe ByteString)] -> Either CodingFailure v {- TODO this is the place where values get made To make it for a custom type you'd need to generate CasValues instances... for instance for Songs, whose type is: Songs :: Data.Text.Internal.Text -> Data.Text.Internal.Text -> Bool -> uuid-types-1.0.3:Data.UUID.Types.Internal.UUID -> Int -> Data.Text.Internal.Text -> Songs The CasValue instance for Songs should look like: instance CasValues Songs where decodeValues vs = do let (a, b, c, d, e, f) = vs Songs <$> a <*> b <*> c <*> d <*> e <*> f How will you apply the CasValues to what's inside of vs though? Won't that be necessary? Here is the original instance for 6 values: instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f) => CasValues (a, b, c, d, e, f) where encodeValues (a, b, c, d, e, f) = encodeNested 0 (a, (b, (c, (d, (e, (f, ())))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, ())))))) -> (a, b, c, d, e, f)) <$> decodeNested 0 vs -} instance CasValues () where encodeValues () types = encodeNested 0 () types decodeValues vs = decodeNested 0 vs instance CasType a => CasValues a where encodeValues a = encodeNested 0 (a, ()) decodeValues vs = (\(a, ()) -> a) <$> decodeNested 0 vs instance (CasType a, CasType b) => CasValues (a, b) where encodeValues (a, b) = encodeNested 0 (a, (b, ())) decodeValues vs = (\(a, (b, ())) -> (a, b)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c) => CasValues (a, b, c) where encodeValues (a, b, c) = encodeNested 0 (a, (b, (c, ()))) decodeValues vs = (\(a, (b, (c, ()))) -> (a, b, c)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d) => CasValues (a, b, c, d) where encodeValues (a, b, c, d) = encodeNested 0 (a, (b, (c, (d, ())))) decodeValues vs = (\(a, (b, (c, (d, ())))) -> (a, b, c, d)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e) => CasValues (a, b, c, d, e) where encodeValues (a, b, c, d, e) = encodeNested 0 (a, (b, (c, (d, (e, ()))))) decodeValues vs = (\(a, (b, (c, (d, (e, ()))))) -> (a, b, c, d, e)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f) => CasValues (a, b, c, d, e, f) where encodeValues (a, b, c, d, e, f) = encodeNested 0 (a, (b, (c, (d, (e, (f, ())))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, ())))))) -> (a, b, c, d, e, f)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g) => CasValues (a, b, c, d, e, f, g) where encodeValues (a, b, c, d, e, f, g) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, ()))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, ()))))))) -> (a, b, c, d, e, f, g)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h) => CasValues (a, b, c, d, e, f, g, h) where encodeValues (a, b, c, d, e, f, g, h) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, ())))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, ())))))))) -> (a, b, c, d, e, f, g, h)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i) => CasValues (a, b, c, d, e, f, g, h, i) where encodeValues (a, b, c, d, e, f, g, h, i) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, ()))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, ()))))))))) -> (a, b, c, d, e, f, g, h, i)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j) => CasValues (a, b, c, d, e, f, g, h, i, j) where encodeValues (a, b, c, d, e, f, g, h, i, j) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, ())))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, ())))))))))) -> (a, b, c, d, e, f, g, h, i, j)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k) => CasValues (a, b, c, d, e, f, g, h, i, j, k) where encodeValues (a, b, c, d, e, f, g, h, i, j, k) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, ()))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, ()))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, ())))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, ())))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, ()))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, ()))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, ())))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, ())))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, ()))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, ()))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, ())))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, ())))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p, CasType q) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, ()))))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, ()))))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p, CasType q, CasType r) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, ())))))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, ())))))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p, CasType q, CasType r, CasType s) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, ()))))))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, ()))))))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p, CasType q, CasType r, CasType s, CasType t) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t, ())))))))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t, ())))))))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p, CasType q, CasType r, CasType s, CasType t, CasType u) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t,(u, ()))))))))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t, (u, ()))))))))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p, CasType q, CasType r, CasType s, CasType t, CasType u, CasType v) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u,v) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t,(u, (v, ())))))))))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t, (u, (v, ())))))))))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p, CasType q, CasType r, CasType s, CasType t, CasType u, CasType v, CasType w) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t,(u, (v, (w, ()))))))))))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t, (u, (v, (w, ()))))))))))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p, CasType q, CasType r, CasType s, CasType t, CasType u, CasType v, CasType w, CasType x) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t,(u, (v, (w, (x, ())))))))))))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t, (u, (v, (w, (x, ())))))))))))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p, CasType q, CasType r, CasType s, CasType t, CasType u, CasType v, CasType w, CasType x, CasType y) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t,(u, (v, (w, (x, (y, ()))))))))))))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t, (u, (v, (w, (x, (y, ()))))))))))))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y)) <$> decodeNested 0 vs instance (CasType a, CasType b, CasType c, CasType d, CasType e, CasType f, CasType g, CasType h, CasType i, CasType j, CasType k, CasType l, CasType m, CasType n, CasType o, CasType p, CasType q, CasType r, CasType s, CasType t, CasType u, CasType v, CasType w, CasType x, CasType y, CasType z) => CasValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) where encodeValues (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z) = encodeNested 0 (a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t,(u, (v, (w, (x, (y, (z, ())))))))))))))))))))))))))) decodeValues vs = (\(a, (b, (c, (d, (e, (f, (g, (h, (i, (j, (k, (l, (m, (n, (o, (p, (q, (r, (s, (t, (u, (v, (w, (x, (y, (z, ())))))))))))))))))))))))))) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)) <$> decodeNested 0 vs -- | Cassandra consistency level. See the Cassandra documentation for an explanation. data Consistency = ANY | ONE | TWO | THREE | QUORUM | ALL | LOCAL_QUORUM | EACH_QUORUM | SERIAL | LOCAL_SERIAL | LOCAL_ONE deriving (Eq, Ord, Show, Bounded, Enum) instance ProtoElt Consistency where putElt c = putWord16be $ case c of ANY -> 0x0000 ONE -> 0x0001 TWO -> 0x0002 THREE -> 0x0003 QUORUM -> 0x0004 ALL -> 0x0005 LOCAL_QUORUM -> 0x0006 EACH_QUORUM -> 0x0007 SERIAL -> 0x0008 LOCAL_SERIAL -> 0x0009 LOCAL_ONE -> 0x000A getElt = do w <- getWord16be case w of 0x0000 -> pure ANY 0x0001 -> pure ONE 0x0002 -> pure TWO 0x0003 -> pure THREE 0x0004 -> pure QUORUM 0x0005 -> pure ALL 0x0006 -> pure LOCAL_QUORUM 0x0007 -> pure EACH_QUORUM 0x0008 -> pure SERIAL 0x0009 -> pure LOCAL_SERIAL 0x000A -> pure LOCAL_ONE _ -> fail $ "unknown consistency value 0x"++showHex w "" -- TODO can I make some function that uses results of executeRaw and allows user to provide typeclasses (including typeclasses based on their custom type) to parse it? f :: Result [Maybe ByteString] -> [ByteString] f = undefined class Decodeable a where mydecode :: [ByteString] -> m a -- execute2 :: (MonadIO m,MonadCassandra m, CasValues i) => Query style any_i any_o -> i -> Consistency -> m a -- execute2 query i cons = do -- res <- withSession (\_ -> executeInternal query i cons) -- mydecode $ f res data MyType = MyType {x :: Int} g :: ByteString -> Maybe Int g = undefined -- instance Decodeable MyType where -- mydecode bs = MyType <$> g (bs !! 0) -- | A low-level function in case you need some rarely-used capabilities. -- TODO Should we have to add the MonadIO constraint? executeRaw :: (MonadIO m, MonadCassandra m, CasValues i) => Query style any_i any_o -> i -> Consistency -> m (Result [Maybe ByteString]) executeRaw query i cons = withSession (\_ -> executeInternal query i cons) executeInternal :: CasValues values => Query style any_i any_o -> values -> Consistency -> StateT ActiveSession IO (Result [Maybe ByteString]) executeInternal query i cons = do (PreparedQuery pqid queryMeta) <- prepare query values <- case encodeValues i (metadataTypes queryMeta) of Left err -> throwM $ ValueMarshallingException TransportSending (T.pack $ show err) (queryText query) Right values -> return values sendFrame $ Frame [] 0 EXECUTE $ runPut $ do putElt pqid putElt cons putWord8 0x01 putWord16be (fromIntegral $ length values) forM_ values $ \mValue -> case mValue of Nothing -> putWord32be 0xffffffff Just value -> do let enc = encodeCas value putWord32be (fromIntegral $ B.length enc) putByteString enc fr <- recvFrame (queryText query) case frOpcode fr of RESULT -> decodeEltM "RESULT" (frBody fr) (queryText query) ERROR -> throwError (queryText query) (frBody fr) _ -> throwM $ LocalProtocolError ("execute: unexpected opcode " `T.append` T.pack (show (frOpcode fr))) (queryText query) -- executeInternalTxt :: Text -> -- | Execute a query that returns rows. -- TODO Should we have to add the MonadIO constraint? executeRows :: (MonadCassandra m, MonadIO m, CasValues i, CasValues o) => Consistency -- ^ Consistency level of the operation -> Query Rows i o -- ^ CQL query to execute -> i -- ^ Input values substituted in the query -> m [o] executeRows cons q i = do res <- executeRaw q i cons case res of RowsResult meta rows -> decodeRows q meta rows _ -> throwM $ LocalProtocolError ("expected Rows, but got " `T.append` T.pack (show res)) (queryText q) -- executeRows' :: (MonadCassandra m, MonadIO m, CasValues i, CasValues o) => -- Consistency -- ^ Consistency level of the operation -- -> Query Rows i o -- ^ CQL query to execute -- -> a -- ^ Input values substituted in the query -- -> m [a] -- executeRows' cons q i = do -- res <- executeRaw q i cons -- case res of -- RowsResult meta rows -> decodeRows q meta rows -- _ -> throwM $ LocalProtocolError ("expected Rows, but got " `T.append` T.pack (show res)) (queryText q) -- | Execute a query that returns a Frames record executeRowsFrames :: (MonadCassandra m, MonadIO m, CasValues i, CasValues o) => Consistency -- ^ Consistency level of the operation -> Query Rows i o -- ^ CQL query to execute -> i -- ^ Input values substituted in the query -> m [o] executeRowsFrames cons q i = do res <- executeRaw q i cons case res of RowsResult meta bytestringRows -> do let txtRows = fmap (fmap T.decodeUtf8) <$> bytestringRows undefined _ -> throwM $ LocalProtocolError ("expected Rows, but got " `T.append` T.pack (show res)) (queryText q) -- | Execute a lightweight transaction (CAS). executeTrans :: (MonadIO m, MonadCassandra m, CasValues i) => Query Write i () -- ^ CQL query to execute -> i -- ^ Input values substituted in the query -> Consistency -- ^ Consistency for the write operation (S in CAS). -> m Bool executeTrans q i c = do res <- executeRaw q i c case res of RowsResult _ ((el:row):rows) -> case decodeCas $ fromJust el of Left s -> error $ "executeTrans: decode result failure=" ++ s Right b -> return b _ -> throwM $ LocalProtocolError ("expected Rows, but got " `T.append` T.pack (show res)) (queryText q) -- | Helper for 'executeRows' useful in situations where you are only expecting one row -- to be returned. executeRow :: (MonadIO m, MonadCassandra m, CasValues i, CasValues o) => Consistency -- ^ Consistency level of the operation -> Query Rows i o -- ^ CQL query to execute -> i -- ^ Input values substituted in the query -> m (Maybe o) executeRow cons q i = do rows <- executeRows cons q i return $ listToMaybe rows getOneSong :: Query 'Rows UUID (Text, Int) getOneSong = "select artist, timesPlayed from songs where id=?" -- exMetadata = Metadata [ColumnSpec (TableSpec (Keyspace "test1") (Table "songs")) "artist" text,ColumnSpec (TableSpec (Keyspace "test1") (Table "songs")) "timesplayed" int] exMetadata = Metadata [ColumnSpec (TableSpec (Keyspace "test1") (Table "songs")) "artist" CText,ColumnSpec (TableSpec (Keyspace "test1") (Table "songs")) "timesplayed" CInt] exRows0 :: [[Maybe B.ByteString]] exRows0 = [[Just "Evanescence",Just "\NUL\NUL\ETX\US"]] -- decodeRows getSongs exMetadata {- Using example values: λ> decodeRows getOneSong exMetadata exRows0 [("Evanescence",799)] -} decodeRows :: (MonadCatch m, CasValues values) => Query Rows any_i values -> Metadata -> [[Maybe ByteString]] -> m [values] decodeRows query meta rows0 = do let meta' = trace ("meta: " ++ show meta) meta let rows0' = trace ("rows0: " ++ show rows0) rows0 let rows1 = flip map rows0' $ \cols -> decodeValues (zip (metadataTypes meta') cols) case lefts rows1 of (err:_) -> throwM $ ValueMarshallingException TransportReceiving (T.pack $ show err) (queryText query) [] -> return () let rows2 = flip map rows1 $ \(Right v) -> v return $ rows2 -- | Execute a write operation that returns void. executeWrite :: (MonadIO m, MonadCassandra m, CasValues i) => Consistency -- ^ Consistency level of the operation -> Query Write i () -- ^ CQL query to execute -> i -- ^ Input values substituted in the query -> m () executeWrite cons q i = do res <- executeRaw q i cons case res of Void -> return () _ -> throwM $ LocalProtocolError ("expected Void, but got " `T.append` T.pack (show res)) (queryText q) -- | Execute a schema change, such as creating or dropping a table. executeSchema :: (MonadIO m, MonadCassandra m, CasValues i) => Consistency -- ^ Consistency level of the operation -> Query Schema i () -- ^ CQL query to execute -> i -- ^ Input values substituted in the query -> m (Change, Keyspace, Table) executeSchema cons q i = do res <- executeRaw q i cons case res of SchemaChange ch ks ta -> return (ch, ks, ta) _ -> throwM $ LocalProtocolError ("expected SchemaChange, but got " `T.append` T.pack (show res)) (queryText q) -- | Executes a schema change that has a void result such as creating types executeSchemaVoid :: (MonadIO m, MonadCassandra m, CasValues i) => Consistency -- ^ Consistency level of the operation -> Query Schema i () -- ^ CQL query to execute -> i -- ^ Input values substituted in the query -> m () executeSchemaVoid cons q i = do res <- executeRaw q i cons case res of Void -> return () _ -> throwM $ LocalProtocolError ("expected Void, but got " `T.append` T.pack (show res)) (queryText q) -- | A helper for extracting the types from a metadata definition. metadataTypes :: Metadata -> [CType] metadataTypes (Metadata colspecs) = map (\(ColumnSpec _ _ typ) -> typ) colspecs -- | The monad used to run Cassandra queries in. newtype Cas a = Cas (ReaderT Pool IO a) deriving (Functor, Applicative, Monad, MonadIO, MonadCatch, MonadThrow) instance MonadCassandra Cas where getCassandraPool = Cas ask -- | Execute Cassandra queries. runCas :: Pool -> Cas a -> IO a runCas pool (Cas code) = runReaderT code pool
the-real-blackh/cassandra-cql
Database/Cassandra/CQL.hs
bsd-3-clause
80,458
1
35
24,848
27,413
15,203
12,210
1,431
17
module Yesod.CoreBot.Bliki.Resources.Base ( module Yesod.CoreBot.Bliki.Resources.Base ) where import Yesod.CoreBot.Bliki.Prelude import Yesod.CoreBot.Bliki.Config import Yesod.CoreBot.Bliki.DB import Yesod.CoreBot.Bliki.Store import Control.Concurrent import Control.Monad.Reader.Class import qualified Data.Text as Text mkYesodSubData "Data_ master" [] [parseRoutes| /latest LatestR GET / UpdateLogR GET /entry/*Texts EntryLatestR GET /blog/#RevisionId BlogR GET /rev/#RevisionId/*Texts EntryRevR GET |] mkYesodSubData "Blog_ master" [] [parseRoutes| / BlogIndexR GET |] mkYesodSubData "Wiki_ master" [] [parseRoutes| /*Texts WikiIndexR GET |] mkYesodSubData "Static" [] [parseRoutes| /#String FileR GET |]
coreyoconnor/corebot-bliki
src/Yesod/CoreBot/Bliki/Resources/Base.hs
bsd-3-clause
867
0
6
230
132
85
47
-1
-1
-- umbralcalculus.hs module Math.UmbralCalculus where import Math.MathsPrimitives (FunctionRep (..), partialProducts, factorials, ($+), ($.) ) import Math.QQ import Math.CombinatoricsCounting import Math.PowerSeries import Math.UPoly -- Sources: -- Robert, A Course in p-adic Analysis -- http://en.wikipedia.org ("umbral calculus", "binomial type", "hermite polynomials", "touchard polynomials") -- COMPOSITION OPERATORS -- A translation is an operator t_a defined by (t_a f) (x) = f (x+a). (It is a linear operator on the vector space of polynomials) -- Robert p198-9 -- A composition operator is a linear operator on the vector space of polynomials that commutes with translations -- The composition operators are precisely the power series in D, the d/dx operator applyCompOp (PS as) f = sum (doApplyCompOp as f) where doApplyCompOp [] _ = [] doApplyCompOp _ 0 = [] doApplyCompOp (a:as) h = let h' = derivUP h in (a */ h) : doApplyCompOp as h' -- DELTA OPERATORS -- Robert, p197 -- A delta operator is a linear operator d on the the space of polynomials, such that -- 1. d commutes with all translations t_a (ie, d is a composition operator) -- 2. d(x) = c, a non-zero constant -- The delta operators are precisely the power series in D, a0 + a1D + ..., with a0 == 0, a1 /= 0 isDeltaOp (PS (a0:a1:_)) = a0 == 0 && a1 /= 0 inverseDeltaOp delta f = integUP (applyCompOp (t/delta) f) -- find g such that delta g == f -- => delta (D g) == D (delta g) == D f -- => D g == 1/delta (D f) = (D/delta) f -- => g = integUP ( (D/delta) f ) -- the basic sequence of a delta operator is the (unique) sequence of polynomials p_n(x) such that -- deg p_n = n -- delta p_n = n p_n-1, n >= 1 -- p_0 = 1; p_n(0) == 0, n >= 1 basicSequence delta | isDeltaOp delta = 1 : doBasicSequence 1 1 where doBasicSequence n f' = let f = inverseDeltaOp delta (fromInteger n */ f') in f : doBasicSequence (n+1) f -- The basic sequence of a delta operator satisfies -- p_n (x+y) == sum [n `choose` k * p_k(x) * p_n-k(y) | k <- [0..n] ] -- This follows from taking the generalised Taylor series of p_n wrt delta around x -- Robert p206, we can calculate the nth poly in the basic sequence directly basicPoly _ 0 = 1 basicPoly delta@(PS (0:as)) n = x * applyCompOp ((recip (PS as))^n) (x^(n-1)) -- SHEFFER SEQUENCES -- Robert, p208 -- A Sheffer sequence (relative to delta) is a sequence of polynomials s_n such that -- 1. deg s_n == n -- 2. delta s_n = n s_n-1, n >= 1 -- The Sheffer sequences are precisely the sequences s_n = S (p_n), where p_n is the basic system of the delta operator d, and S is an invertible composition operator isInvertible (PS (a0:_)) = a0 /= 0 shefferSequence delta s | isInvertible s = map (applyCompOp s) (basicSequence delta) | otherwise = error "shefferSequence: s is not invertible" -- A Sheffer sequence wrt the differentiation operator D is called an Appell sequence appellSequence = shefferSequence t -- Robert p 208 -- A Sheffer sequence satisfies -- s_n(x+y) == sum [n `choose` k * p_k(x) * s_n-k(y) | k <- [0..n] ] -- In particular, an Appell sequence satisfies -- s_n(x+y) == sum [n `choose` k * x^k * s_n-k(y) | k <- [0..n] ] -- GENERALISED MACLAURIN SERIES -- Given a delta operator, with basic sequence p0, p1, ..., and a polynomial f -- The generalised Maclaurin series is f == f(0) p0 + (delta f)(0) p1(x) + (delta delta f)(0) p2(x) / 2! + ... -- returns the terms f(0), (delta f)(0), (delta delta f)(0), ... genMaclaurinDerivsUP _ 0 = [] genMaclaurinDerivsUP delta f = evalUP f 0 : genMaclaurinDerivsUP delta (applyCompOp delta f) -- returns the terms f(0)/0!, (delta f)(0)/1!, (delta delta f)(0)/2!, etc genMaclaurinCoeffsUP delta f = zipWith (/) (genMaclaurinDerivsUP delta f) (map fromInteger factorials) -- So we expect that -- sum (zipWith (*/) (genMaclaurinCoeffsUP delta f) (basicSequence delta)) == f -- Examples: -- genMaclaurinCoeffsUP t (x^2-x) == [0,-1,1] - it just returns the poly -- from Cameron, Combinatorics, p81 -- (x)_n = sum s(n,k) x^k -- => genMaclaurinCoeffsUP t (fallingFactorial x (toInteger n)) == map fromInteger (stirlingFirstTriangle !! n) -- x^n = sum S(n,k) (x)_k -- => genMaclaurinCoeffsUP (exp t - 1) (x^n) == map fromInteger (stirlingSecondTriangle !! n) -- We could also do Taylor series, ie evaluate the derivatives at an arbitrary point, rather than zero -- BERNOULLI POLYNOMIALS -- Bernoulli polynomials via recurrence relation, Robert p272 bernoulliPolys = b0 : doBernoulliPolys [1,2,1] [b0] 1 where b0 = fromInteger 1 :: UPoly QQ doBernoulliPolys cs bs n = let cs' = nextPascal cs b = x^n - (1 / fromInteger (n+1)) */ (cs $. bs) in b : doBernoulliPolys cs' (bs++[b]) (n+1) -- Bernoulli polynomial via explicit expression, Robert p271 bernoulliPoly' m = sum [fromInteger (m `choose` k) * bernoulliNumber (fromEnum k) */ (x^(m-k)) | k <- [0..m] ] bernoulliPoly m = applyCompOp bernoulliEGF (x^m) -- (faster) bernoulliSS = appellSequence bernoulliEGF -- HERMITE POLYNOMIALS -- from http://en.wikipedia.org/wiki/Hermite_polynomials -- Hermite polys can be defined by the recurrence relation H_n+1 (x) = x H_n(x) - d/dx H_n(x) hermitePolys = doHermitePolys 1 where doHermitePolys f = f : doHermitePolys (x * f - derivUP f) hermitePoly n = hermitePolys !! n -- the hermite polys can be derived as terminating power series -- hermite n = (-1)^n * e^(t^2/2) * D^n (e^(-t^2/2)) hermite n = (-1)^n * exp ((t^2)/2) * ((iterate deriv (exp (-(t^2)/2))) !! n) hermitePS = exp (-(t^2)/2) -- alternatively, the Hermite polys can be got by applying e^(-(D^2)/2) to the powers x^n hermitePoly' n = applyCompOp hermitePS (x^n) hermiteSS = appellSequence hermitePS -- combinatorial interpretation -- the coefficient of x^k in H_n(x) is the number of unordered partitions of n into k singletons and (n-k)/2 pairs -- eg H4(x) = x^4 - 6 x^2 + 3 -- so there are 6 partitions of 4 into 2 singletons and 1 pair, namely -- [[1,2],[3],[4]], [[1,3],[2],[4]], [[1,4],[2],[3]], [[1],[2,3],[4]], [[1],[2,4],[3]], [[1],[2],[3,4]] -- TOUCHARD POLYNOMIALS -- from http://en.wikipedia.org/wiki/Touchard_polynomials -- (called Bell polynomials by Robert, p211) -- using the recursion T_n+1(x) = x * sum [(n `choose` k) * T_k(x) | k <- [0..n] ] touchardPolys = b0 : doTouchardPolys [1] [b0] where b0 = fromInteger 1 :: UPoly QQ doTouchardPolys cs bs = let cs' = nextPascal cs b = x * (cs $. bs) in b : doTouchardPolys cs' (b:bs) -- the Touchard polynomials are the basic sequence for the delta operator log(1+D) touchardPolys' = basicSequence log1PS touchardPoly n = UP (map fromInteger (stirlingSecondTriangle !! n)) touchardPoly' n = touchardPolys !! n -- evalUP (touchardPoly n) 1 == bellNumber n touchardSS = shefferSequence log1PS 1 -- LAGUERRE POLYNOMIALS -- modified from Dan's code laguerreSS nu = shefferSequence (t/(1-t)) ((1-t)^(nu+1)) -- laguerre0 n = e^t / n! * D^n (e^-t * t^n) laguerre0 0 = 1 laguerre0 n = exp t / fromInteger (product [1..toInteger n]) * ((iterate deriv (exp (-t) * (t^n))) !! n) laguerre nu n = ((iterate deriv (t^(n+nu) * exp (-t))) !! n) * exp t / (factorial n * t^nu) where factorial n = fromInteger (product [1..toInteger n]) -- !! NOT WORKING - gives wrong answer -- from recurrence relation, Hassani, Mathematical Physics: A Modern Introduction to its Foundations, p181 laguerrePolys nu = 1 : f1 : doLaguerrePolys (1,f1,1) where f1 = x - (fromInteger nu + 1) doLaguerrePolys (n, f_n, f_n_1) = let f = recip (n+1) */ ( ((2*n + fromInteger nu + 1) */ f_n) - (x * f_n) - ((n + fromInteger nu) */ f_n_1) ) in f : doLaguerrePolys (n+1,f,f_n) -- VARIANT CODE -- find g such that delta g == f, by "integrating" termwise -- note that the following algorithm only works for delta operators, because it requires that deg (delta f) == deg f - 1 inverseDeltaOp' delta f | f == 0 = 0 | isDeltaOp delta = let n = degUP f xn1 = x^(n+1) xn1' = applyCompOp delta xn1 lcg = lcUP f / lcUP xn1' in lcg */ xn1 + inverseDeltaOp delta (f - lcg */ xn1') | otherwise = error ("inverseDeltaOp: " ++ show delta ++ " is not a delta operator") -- POWER SERIES IN DIFF OPS _D f = derivUP f _xD f = x * derivUP f _Dx f = derivUP (x*f) _Dx_xD f = _Dx f - _xD f -- !! But applying either _xD or _Dx doesn't terminate on polys applyPS op (PS as) f = sum (doApplyPS as f) where doApplyPS [] _ = [] doApplyPS _ 0 = [] doApplyPS (a:as) h = let h' = op h in (a */ h) : doApplyPS as h'
nfjinjing/bench-euler
src/Math/UmbralCalculus.hs
bsd-3-clause
8,750
17
20
1,919
1,914
1,015
899
86
3
module Reactive.Banana.GLFW.Utils where import Control.Monad import Control.Exception import Graphics.UI.GLFW as GLFW withGLFW :: IO () -> IO () withGLFW = bracket_ (assertIO =<< GLFW.init) GLFW.terminate where assertIO b = unless b $ ioError $ userError "withGLFW"
cdxr/reactive-banana-glfw
Reactive/Banana/GLFW/Utils.hs
bsd-3-clause
276
0
9
46
90
49
41
7
1
{-# LANGUAGE RecursiveDo #-} {-# LANGUAGE FlexibleContexts #-} import Prelude () import ClassyPrelude import Reflex import Reflex.Dom -- import Common -- -- import Bootstrap import PureCSS import SortableTable -- toComponent :: Component B a => a -> CompBackend B a -- toComponent comp = wrapComponent comp fontAwesome :: (MonadWidget t m) => m () fontAwesome = elAttr "link" ( "rel" =: "stylesheet" <> "href" =: "font-awesome-4.6.3/css/font-awesome.css" ) blank -- data Sorting = Ascending | Descending | NotSorted -- createSortHeadCell :: MonadWidget t m => (Int, String, Sorting) -> m (Event t Int) -- createSortHeadCell (idx, item, sorting) = do -- (e, _) <- el' "div" $ do -- text item -- showArrow -- el "span" blank -- return $ pushAlways (const (return idx)) $ domEvent Click e -- showArrow :: MonadWidget t m => Sorting -> m () -- showArrow Ascending = elAttr "i" ("class" =: "fa fa-long-arrow-down") -- showArrow Descending = elAttr "i" ("class" =: "fa fa-long-arrow-up") -- showArrow NotSorted = blank -- thead :: MonadWidget t m => [String] -> [m (Event t Int)] -- thead cts = fmap createSortHeadCell $ zip3 [0..] cts $ repeat NotSorted -- -- thead :: [String] -- -- thead = ["First", "Second"] -- tbody :: MonadWidget t m => [[Int]] -> [[m ()]] -- tbody contents = do -- (fmap . fmap) (text . show) contents -- bodyContents :: [[Int]] -- bodyContents = [ [1, 3] -- , [4, 2] -- , [7, 5] -- , [4, 1] -- , [1, 9] -- , [2, 14] -- , [13, 93] -- ] -- -- -- Takes in a collection of cells and displays them -- -- dispCells :: (Traversable t, MonadWidget t1 m) => String -> t (m b) -> m (t b) -- -- dispCells label cells = el "tr" $ mapM dispCell cells -- -- where -- -- dispCell = el label -- dispTable :: MonadWidget t m => m () -- dispTable = elAttr "table" ("class" =: "pure-table pure-table-striped") $ do -- evts <- el "thead" $ dispCells "th" thead -- let leftEvent = leftmost evts -- folded <- foldDyn (\idx (idxOld, revBool) -> case idx == idxOld of -- True -> (idx, not revBool) -- False -> (idx, False) -- ) (0, False) leftEvent -- sorted <- mapDyn (\(idx, revBool) -> shouldReverse revBool $ sortTable idx) folded -- el "tbody" $ -- simpleList sorted (\x -> el "tr" $ -- simpleList x (\y -> el "td" $ dynText =<< mapDyn show y) -- ) -- return () -- mainView :: MonadWidget t m => m () -- mainView = do -- dispTable -- sortTable :: Int -> [[Int]] -- sortTable idx = sortOn (flip indexEx idx) bodyContents -- items :: [Int] -- items = [1,5,3,4] -- shouldReverse :: Bool -> [a] -> [a] -- shouldReverse False items = items -- shouldReverse True items = reverse items main :: IO () main = mainWidgetWithHead (fontAwesome >> header) $ do testTable
limaner2002/ghcjs-test
app/Main.hs
bsd-3-clause
3,251
0
9
1,083
167
119
48
15
1
{-# LANGUAGE CPP, Rank2Types #-} module Control.Monad.IO.Logic ( LogicIO , runLogicIO , observeIO , observeAllIO , observeManyIO , liftST ) where #ifdef MODULE_Control_Monad_ST_Safe import Control.Monad.ST.Safe #else import Control.Monad.ST #endif import Control.Monad.ST.Logic.Internal hiding (liftST) import qualified Control.Monad.ST.Logic.Internal as Internal type LogicIO s = LogicT s IO runLogicIO :: (forall s . LogicIO s a) -> (a -> IO r -> IO r) -> IO r -> IO r runLogicIO = runLogicT {-# INLINE runLogicIO #-} observeIO :: (forall s . LogicIO s a) -> IO a observeIO = observeT {-# INLINE observeIO #-} observeAllIO :: (forall s . LogicIO s a) -> IO [a] observeAllIO = observeAllT {-# INLINE observeAllIO #-} observeManyIO :: Int -> (forall s . LogicIO s a) -> IO [a] observeManyIO = observeManyT {-# INLINE observeManyIO #-} liftST :: ST RealWorld a -> LogicIO s a liftST = Internal.liftST {-# INLINE liftST #-}
sonyandy/logicst
src/Control/Monad/IO/Logic.hs
bsd-3-clause
978
0
10
202
265
155
110
27
1
{-# LANGUAGE TupleSections #-} module Main (main) where import Criterion.Main import qualified Data.Map.Strict as M import ADEL mapUpTo :: Int -> M.Map Int () mapUpTo x = M.fromList $ map (,()) [0 .. x] findNofM :: Int -> Int -> Benchmark findNofM numToFind totalNum = if numToFind > totalNum then bench "numToFind > totalNum" $ nfIO (return ()) --error "findNofM numToFind > totalNum" else env (return (mapUpTo numToFind, mapUpTo totalNum)) (\ ~(find, whole) -> bench ("find " ++ show numToFind ++ " of " ++ show totalNum) (nfIO $ minimalSubmapSatisfying whole (return . M.isSubmapOf find))) findHalf :: Int -> Benchmark findHalf n = findNofM (n `div` 2) n findNone :: Int -> Benchmark findNone = findNofM 0 findAll :: Int -> Benchmark findAll n = findNofM n n range = [0, 2500..100000] main = defaultMain $ concat [map findHalf [0,2500..20000], map findAll range, map findNone range, map (findNofM 20) range, map (findNofM 50) range]
enolan/reducecase
bench/Main.hs
bsd-3-clause
1,004
0
16
222
373
199
174
28
2
{-# LANGUAGE PatternGuards, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances, FlexibleInstances, TypeSynonymInstances, StandaloneDeriving #-} -- | Duck Types module Type ( module Gen.Type , IsType(..) , TypeEnv , substVoid , singleton , unsingleton , freeVars , generalType , deStatic, unStatic -- * Transformation annotations , TransType -- * Datatypes , Datatype, makeDatatype , dataName, dataLoc, dataTyVars, dataInfo, dataVariances ) where import Data.Functor import Data.Map (Map) import qualified Data.Map as Map import Pretty import SrcLoc import Var import Memory -- Pull in autogenerated code import Gen.Type -- Add instance declarations deriving instance Eq t => Eq (TypeFun t) deriving instance Ord t => Ord (TypeFun t) deriving instance Show t => Show (TypeFun t) deriving instance Show Any deriving instance Show TypeVal deriving instance Eq TypePat deriving instance Ord TypePat deriving instance Show TypePat deriving instance Eq Trans deriving instance Ord Trans deriving instance Show Trans deriving instance Eq Variance type TypeEnv = Map Var TypeVal -- |A type with an associated Transform to be applied to the value. type TransType t = (Trans, t) instance HasVar TypePat where unVar (TsVar v) = Just v unVar _ = Nothing class IsType t where typeCons :: Datatype -> [t] -> t typeFun :: [TypeFun t] -> t typeVoid :: t unTypeCons :: t -> Maybe (Datatype, [t]) unTypeFun :: t -> Maybe [TypeFun t] typePat :: t -> TypePat instance IsType TypeVal where typeCons = TyCons typeFun = TyFun typeVoid = TyVoid unTypeCons (TyCons c a) = Just (c,a) unTypeCons _ = Nothing unTypeFun (TyFun f) = Just f unTypeFun _ = Nothing typePat = singleton instance IsType TypePat where typeCons = TsCons typeFun = TsFun typeVoid = TsVoid unTypeCons (TsCons c a) = Just (c,a) unTypeCons _ = Nothing unTypeFun (TsFun f) = Just f unTypeFun _ = Nothing typePat = id -- |See definition of Datatype in type.duck type Datatype = Box DataType makeDatatype :: CVar -> SrcLoc -> [Var] -> [Variance] -> DataInfo -> Datatype makeDatatype n l args vl info = box $ Data n l args vl info dataName :: Datatype -> CVar dataName = dataTypeName . unbox dataLoc :: Datatype -> SrcLoc dataLoc = dataTypeLoc . unbox dataTyVars :: Datatype -> [Var] dataTyVars = dataTypeVars . unbox dataInfo :: Datatype -> DataInfo dataInfo = dataTypeInfo . unbox dataVariances :: Datatype -> [Variance] dataVariances = dataTypeVariances . unbox instance HasLoc Datatype where loc = dataLoc -- |Compare and show datatypes based on their names to avoid recursion instance Eq Datatype where a == b = dataName a == dataName b instance Ord Datatype where compare a b = compare (dataName a) (dataName b) instance Show Datatype where show = show . dataName instance Pretty Datatype where pretty' = pretty' . dataName -- |Type environment substitution subst :: TypeEnv -> TypePat -> TypePat subst env (TsVar v) | Just t <- Map.lookup v env = singleton t | otherwise = TsVar v subst env (TsCons c tl) = TsCons c (map (subst env) tl) subst env (TsFun f) = TsFun (map fun f) where fun (FunArrow tr s t) = FunArrow tr (subst env s) (subst env t) fun (FunClosure f tl) = FunClosure f (map (subst env) tl) subst _ TsVoid = TsVoid _subst = subst -- |Type environment substitution with unbound type variables defaulting to void substVoid :: TypeEnv -> TypePat -> TypeVal substVoid env (TsVar v) = Map.findWithDefault TyVoid v env substVoid env (TsCons c tl) = TyCons c (map (substVoid env) tl) substVoid env (TsFun f) = TyFun (map fun f) where fun (FunArrow tr s t) = FunArrow tr (substVoid env s) (substVoid env t) fun (FunClosure f tl) = FunClosure f (map (substVoid env) tl) substVoid _ TsVoid = TyVoid -- |Occurs check occurs :: TypeEnv -> Var -> TypePat -> Bool occurs env v (TsVar v') | Just t <- Map.lookup v' env = occurs' v t occurs _ v (TsVar v') = v == v' occurs env v (TsCons _ tl) = any (occurs env v) tl occurs env v (TsFun f) = any fun f where fun (FunArrow _ s t) = occurs env v s || occurs env v t fun (FunClosure _ tl) = any (occurs env v) tl occurs _ _ TsVoid = False _occurs = occurs -- |Types contains no variables occurs' :: Var -> TypeVal -> Bool occurs' _ _ = False -- |This way is easy -- -- For convenience, we overload the singleton function a lot. class Singleton a b | a -> b where singleton :: a -> b instance Singleton TypeVal TypePat where singleton (TyCons c tl) = TsCons c (singleton tl) singleton (TyFun f) = TsFun (singleton f) singleton (TyStatic (Any t _)) = singleton t singleton TyVoid = TsVoid instance Singleton a b => Singleton [a] [b] where singleton = map singleton instance Singleton a b => Singleton (TypeFun a) (TypeFun b) where singleton (FunArrow tr s t) = FunArrow tr (singleton s) (singleton t) singleton (FunClosure f tl) = FunClosure f (singleton tl) -- |Convert a singleton typeset to a type if possible unsingleton :: TypeEnv -> TypePat -> Maybe TypeVal unsingleton env (TsVar v) | Just t <- Map.lookup v env = Just t unsingleton _ (TsVar _) = Nothing unsingleton env (TsCons c tl) = TyCons c <$> mapM (unsingleton env) tl unsingleton env (TsFun f) = TyFun <$> mapM (unsingletonFun env) f unsingleton _ TsVoid = Just TyVoid unsingletonFun :: TypeEnv -> TypeFun TypePat -> Maybe (TypeFun TypeVal) unsingletonFun env (FunArrow tr s t) = do s <- unsingleton env s t <- unsingleton env t return (FunArrow tr s t) unsingletonFun env (FunClosure f tl) = FunClosure f <$> mapM (unsingleton env) tl -- |Find the set of free variables in a typeset freeVars :: TypePat -> [Var] freeVars (TsVar v) = [v] freeVars (TsCons _ tl) = concatMap freeVars tl freeVars (TsFun fl) = concatMap f fl where f (FunArrow _ s t) = freeVars s ++ freeVars t f (FunClosure _ tl) = concatMap freeVars tl freeVars TsVoid = [] generalType :: [a] -> ([TypePat], TypePat) generalType vl = (tl,r) where r : tl = map TsVar (take (length vl + 1) standardVars) -- TODO: closures? deStatic :: TypeVal -> TypeVal deStatic (TyStatic (Any t _)) = t deStatic t = t unStatic :: TypeVal -> Maybe Value unStatic (TyStatic (Any _ v)) = Just v unStatic _ = Nothing -- Pretty printing instance Pretty TypePat where pretty' (TsVar v) = pretty' v pretty' (TsCons t []) = pretty' t pretty' (TsCons t tl) | isTuple (dataName t) = 3 #> punctuate ',' tl pretty' (TsCons t tl) = prettyap t tl pretty' (TsFun f) = pretty' f pretty' TsVoid = pretty' "Void" instance (Pretty t, IsType t) => Pretty (TypeFun t) where pretty' (FunClosure f []) = pretty' f pretty' (FunClosure f tl) = prettyap f tl pretty' (FunArrow NoTrans s t) = 1 #> s <+> "->" <+> pguard 1 t pretty' (FunArrow tr s t) = 1 #> (tr, s) <+> "->" <+> pguard 1 t instance (Pretty t, IsType t) => Pretty [TypeFun t] where pretty' [f] = pretty' f pretty' fl = 5 #> punctuate '&' fl instance Pretty Trans where pretty' NoTrans = pretty' "<no transform>" pretty' Delay = pretty' "delay" pretty' Static = pretty' "static" instance Pretty t => Pretty (TransType t) where pretty' (NoTrans, t) = pretty' t pretty' (c, t) = prettyap c [t]
girving/duck
duck/Type.hs
bsd-3-clause
7,153
0
12
1,444
2,764
1,401
1,363
176
2
{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-| Module : Numeric.AERN.RefinementOrderRounding Description : common arithmetical operations rounded in/out Copyright : (c) Michal Konecny License : BSD3 Maintainer : [email protected] Stability : experimental Portability : portable Common arithmetical operations rounded in/out. This module is meant to be imported qualified. It is recommended to use the prefix ArithInOut. -} module Numeric.AERN.RealArithmetic.RefinementOrderRounding ( module Numeric.AERN.RealArithmetic.RefinementOrderRounding.Conversion, module Numeric.AERN.RealArithmetic.RefinementOrderRounding.FieldOps, module Numeric.AERN.RealArithmetic.RefinementOrderRounding.MixedFieldOps, module Numeric.AERN.RealArithmetic.RefinementOrderRounding.SpecialConst, module Numeric.AERN.RealArithmetic.RefinementOrderRounding.Elementary, RoundedReal(..), dblToReal, dbldblToReal ) where import Numeric.AERN.RealArithmetic.RefinementOrderRounding.Conversion import Numeric.AERN.RealArithmetic.RefinementOrderRounding.FieldOps import Numeric.AERN.RealArithmetic.RefinementOrderRounding.MixedFieldOps import Numeric.AERN.RealArithmetic.RefinementOrderRounding.SpecialConst import Numeric.AERN.RealArithmetic.RefinementOrderRounding.Elementary import Numeric.AERN.RealArithmetic.ExactOps import Numeric.AERN.RealArithmetic.Measures import qualified Numeric.AERN.RealArithmetic.NumericOrderRounding as ArithUpDn import qualified Numeric.AERN.NumericOrder as NumOrd import qualified Numeric.AERN.RefinementOrder as RefOrd import Numeric.AERN.Basics.Effort import Numeric.AERN.Basics.SizeLimits {-| An aggregate class collecting together all functionality normally expected from inward/outward rounded approximations to real numbers such as real intervals with floating-point endpoints. It also provides a single aggregate effort indicator type from which effort indicators for all the rounded operations can be extracted. -} class (HasZero t, HasOne t, HasInfinities t, Neg t, NumOrd.PartialComparison t, NumOrd.RefinementRoundedLattice t, RefOrd.PartialComparison t, RefOrd.RoundedLattice t, HasImprecision t, -- NumOrd.PartialComparison (Imprecision t), RoundedField (Imprecision t), HasDistance t, -- NumOrd.PartialComparison (Distance t), RoundedField (Distance t), Convertible t t, ArithUpDn.Convertible t t, Convertible Int t, ArithUpDn.Convertible t Int, Convertible Integer t, ArithUpDn.Convertible t Integer, Convertible Double t, ArithUpDn.Convertible t Double, Convertible Rational t, ArithUpDn.Convertible t Rational, RoundedAbs t, RoundedField t, RoundedMixedField t t, RoundedMixedField t Int, RoundedMixedField t Integer, RoundedMixedField t Double, RoundedMixedField t Rational, HasSizeLimits t, CanChangeSizeLimits t, EffortIndicator (SizeLimits t), EffortIndicator (RoundedRealEffortIndicator t)) => RoundedReal t where type RoundedRealEffortIndicator t roundedRealDefaultEffort :: t -> RoundedRealEffortIndicator t rrEffortNumComp :: t -> (RoundedRealEffortIndicator t) -> (NumOrd.PartialCompareEffortIndicator t) rrEffortMinmaxInOut :: t -> (RoundedRealEffortIndicator t) -> (NumOrd.MinmaxInOutEffortIndicator t) rrEffortRefComp :: t -> (RoundedRealEffortIndicator t) -> (RefOrd.PartialCompareEffortIndicator t) rrEffortPartialJoin :: t -> (RoundedRealEffortIndicator t) -> (RefOrd.PartialJoinEffortIndicator t) rrEffortJoinMeet :: t -> (RoundedRealEffortIndicator t) -> (RefOrd.JoinMeetEffortIndicator t) rrEffortImprecision :: t -> (RoundedRealEffortIndicator t) -> (ImprecisionEffortIndicator t) -- rrEffortImprecisionComp :: t -> (RoundedRealEffortIndicator t) -> (NumOrd.PartialCompareEffortIndicator (Imprecision t)) -- rrEffortImprecisionField :: t -> (RoundedRealEffortIndicator t) -> (FieldOpsEffortIndicator (Imprecision t)) rrEffortDistance :: t -> (RoundedRealEffortIndicator t) -> (DistanceEffortIndicator t) -- rrEffortDistanceComp :: t -> (RoundedRealEffortIndicator t) -> (NumOrd.PartialCompareEffortIndicator (Distance t)) -- rrEffortDistanceField :: t -> (RoundedRealEffortIndicator t) -> (FieldOpsEffortIndicator (Distance t)) rrEffortToSelf :: t -> (RoundedRealEffortIndicator t) -> (ArithUpDn.ConvertEffortIndicator t t) rrEffortToInt :: t -> (RoundedRealEffortIndicator t) -> (ArithUpDn.ConvertEffortIndicator t Int) rrEffortFromInt :: t -> (RoundedRealEffortIndicator t) -> (ConvertEffortIndicator Int t) rrEffortToInteger :: t -> (RoundedRealEffortIndicator t) -> (ArithUpDn.ConvertEffortIndicator t Integer) rrEffortFromInteger :: t -> (RoundedRealEffortIndicator t) -> (ConvertEffortIndicator Integer t) rrEffortToDouble :: t -> (RoundedRealEffortIndicator t) -> (ArithUpDn.ConvertEffortIndicator t Double) rrEffortFromDouble :: t -> (RoundedRealEffortIndicator t) -> (ConvertEffortIndicator Double t) rrEffortToRational :: t -> (RoundedRealEffortIndicator t) -> (ArithUpDn.ConvertEffortIndicator t Rational) rrEffortFromRational :: t -> (RoundedRealEffortIndicator t) -> (ConvertEffortIndicator Rational t) rrEffortAbs :: t -> (RoundedRealEffortIndicator t) -> (AbsEffortIndicator t) rrEffortField :: t -> (RoundedRealEffortIndicator t) -> (FieldOpsEffortIndicator t) rrEffortSelfMixedField :: t -> (RoundedRealEffortIndicator t) -> (MixedFieldOpsEffortIndicator t t) rrEffortIntMixedField :: t -> (RoundedRealEffortIndicator t) -> (MixedFieldOpsEffortIndicator t Int) rrEffortIntegerMixedField :: t -> (RoundedRealEffortIndicator t) -> (MixedFieldOpsEffortIndicator t Integer) rrEffortDoubleMixedField :: t -> (RoundedRealEffortIndicator t) -> (MixedFieldOpsEffortIndicator t Double) rrEffortRationalMixedField :: t -> (RoundedRealEffortIndicator t) -> (MixedFieldOpsEffortIndicator t Rational) dbldblToReal :: (RoundedReal real) => real -> Double -> Double -> real dbldblToReal sampleReal l r = (dblToReal sampleReal l) `union` (dblToReal sampleReal r) where union = RefOrd.meetOutEff (RefOrd.joinmeetDefaultEffort sampleReal) dblToReal :: (RoundedReal real) => real -> Double -> real dblToReal sampleReal d = mixedAddOutEff (mixedAddDefaultEffort sampleReal d) z d where z = zero sampleReal
michalkonecny/aern
aern-real/src/Numeric/AERN/RealArithmetic/RefinementOrderRounding.hs
bsd-3-clause
6,569
0
11
1,053
1,209
666
543
87
1
import qualified Cookbook.Project.Quill.Quill2.Meta as Qm import qualified Cookbook.Essential.Meta as Cm import qualified Cookbook.Ingredients.Lists.Modify as Md import System.IO import System.Environment import System.Exit import WagesConf main = do arguments <- getArgs if null arguments then wRepl else dispatch arguments dispatch :: [String] -> IO () dispatch ("add":x) = do wf <- wfDB fN <- fmap qError (wfName) Qm.toFile fN (qError (Qm.addItem wf (Qm.AList ("wages",(head x))))) putStrLn "Added" dispatch ("eval":x) = do wF <- wfDB fN <- fmap qError (wfName) splitUp <- getSplits mapM_ (pPrint (read (head x) :: Double)) splitUp where pPrint a (b,c) = do putStrLn $ b ++ " : " ++ (show (a * c)) dispatch ("evalAdd":x) = do dispatch ("eval":x) dispatch ("add":x) dispatch [] = return () dispatch (x:xs) = dispatch xs wRepl = do cmd <- Cm.prompt "$ " dispatch (Md.splitOn cmd ' ')
natepisarski/Wages
Wages.hs
bsd-3-clause
935
0
16
187
410
211
199
31
2
----------------------------------------------------------------------------- -- | -- Module : Examples.Puzzles.Temperature -- Copyright : (c) Levent Erkok -- License : BSD3 -- Maintainer : [email protected] -- Stability : experimental -- -- Puzzle: -- What 2 digit fahrenheit/celcius values are reverses of each other? -- Ignoring the fractions in the conversion ----------------------------------------------------------------------------- module Examples.Puzzles.Temperature where import Data.SBV type Temp = SInteger -- convert celcius to fahrenheit, rounding up/down properly -- we have to be careful here to make sure rounding is done properly.. d2f :: Temp -> Temp d2f d = 32 + ite (fr .>= 5) (1+fi) fi where (fi, fr) = (18 * d) `sQuotRem` 10 -- puzzle: What 2 digit fahrenheit/celcius values are reverses of each other? revOf :: Temp -> SBool revOf c = swap (digits c) .== digits (d2f c) where digits x = x `sQuotRem` 10 swap (a, b) = (b, a) puzzle :: IO () puzzle = do res <- allSat $ revOf `fmap` exists_ cnt <- displayModels disp res putStrLn $ "Found " ++ show cnt ++ " solutions." where disp :: Int -> (Bool, Integer) -> IO () disp _ (_, x) = putStrLn $ " " ++ show x ++ "C --> " ++ show (round f :: Integer) ++ "F (exact value: " ++ show f ++ "F)" where f :: Double f = 32 + (9 * fromIntegral x) / 5
Copilot-Language/sbv-for-copilot
SBVUnitTest/Examples/Puzzles/Temperature.hs
bsd-3-clause
1,429
0
13
344
357
196
161
18
1
{-# LANGUAGE MultiParamTypeClasses #-} module Haspec.Procedure where data Procedure dataType propertyType = Procedure { name :: String, docstring :: String, arguments :: [(String, dataType, propertyType)], returnType :: (dataType, propertyType) } deriving (Ord, Eq, Show)
MaximilianAlgehed/Haspec
src/Haspec/Procedure.hs
bsd-3-clause
568
0
10
330
75
48
27
8
0
-- | like Maybe, but Nothing is shown as question mark module String_Matching.Option where import Autolib.ToDoc import Autolib.Reader import Autolib.Set import Data.Typeable data Option a = Yes a | No deriving ( Eq, Ord ) instance ToDoc a => ToDoc ( Option a ) where toDoc ( Yes a ) = toDoc a toDoc No = text "?" instance Reader a => Reader ( Option a ) where reader = do my_symbol "?" ; return No <|> do x <- reader ; return $ Yes x yes :: [ Option a ] -> Int yes xs = sum $ do Yes x <- xs ; return 1 class Sub a b where sub :: a -> b -> Bool inject :: b -> a instance Eq a => Sub ( Option a ) a where sub No _ = True sub ( Yes x ) y = x == y inject = Yes instance Eq a => Sub ( Option a ) ( Option a ) where sub No _ = True sub ( Yes x ) ( Yes y ) = x == y sub _ _ = False inject = id instance Sub a b => Sub [a] [b] where sub [] [] = True sub (x:xs) (y:ys) = sub x y && sub xs ys sub _ _ = False inject = fmap inject instance (Ord a, Ord b, Sub a b) => Sub (Set a) (Set b) where sub xs ys = sub ( setToList xs ) ( setToList ys ) inject = smap inject
florianpilz/autotool
src/String_Matching/Option.hs
gpl-2.0
1,159
0
10
365
551
277
274
-1
-1
{- Problem 48: Self powers The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317. Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000. -} module Problem48 where solve = (sum [x^x `mod` 10^10 | x<-[1..1000]]) `mod` 10^10
ajsmith/project-euler-solutions
src/Problem48.hs
gpl-2.0
249
0
12
54
56
33
23
2
1
{-| Module : PhaseLexer License : GPL Maintainer : [email protected] Stability : experimental Portability : portable -} module Helium.Main.PhaseLexer(phaseLexer) where import Helium.Main.CompileUtils import Helium.Parser.Lexer import Helium.Parser.LayoutRule(layout) phaseLexer :: String -> String -> [Option] -> Phase LexerError ([LexerWarning], [Token]) phaseLexer fullName contents options = do enterNewPhase "Lexing" options case lexer options fullName contents of Left lexError -> return (Left [lexError]) Right (tokens, lexerWarnings) -> do let tokensWithLayout = layout tokens when (DumpTokens `elem` options) $ print tokensWithLayout let warnings = filterLooksLikeFloatWarnings lexerWarnings tokensWithLayout return (Right (warnings, tokensWithLayout)) -- Throw away the looks like float warnings between the keywords "module" -- and "where". filterLooksLikeFloatWarnings :: [LexerWarning] -> [Token] -> [LexerWarning] filterLooksLikeFloatWarnings warnings tokens = case tokens of (_, LexKeyword "module"):_ -> case dropWhile test tokens of (sp, _):_ -> filter (predicate sp) warnings _ -> warnings _ -> warnings where test (_, t) = t /= LexKeyword "where" predicate sp1 (LexerWarning sp2 w) = not (sp2 <= sp1 && isLooksLikeFloatWarningInfo w)
roberth/uu-helium
src/Helium/Main/PhaseLexer.hs
gpl-3.0
1,482
0
15
391
372
194
178
29
3
{-# LANGUAGE ForeignFunctionInterface, FlexibleInstances #-} ----------------------------------------------------------------------------------------- {-| Module : Types Copyright : (c) Daan Leijen 2003 License : wxWindows Maintainer : [email protected] Stability : provisional Portability : portable Basic types and operations. -} ----------------------------------------------------------------------------------------- module Graphics.UI.WXCore.Types( -- * Objects ( # ) , Object, objectNull, objectIsNull, objectCast, objectIsManaged , objectDelete , withObjectPtr, withObjectRef , withObjectResult, withManagedObjectResult , objectFinalize, objectNoFinalize , objectFromPtr, managedObjectFromPtr -- , Managed, managedNull, managedIsNull, managedCast, createManaged, withManaged, managedTouch -- * Identifiers , Id, idAny, idCreate -- * Bits , (.+.), (.-.) , bits , bitsSet -- * Control , unitIO, bracket, bracket_, finally, finalize, when -- * Variables , Var, varCreate, varGet, varSet, varUpdate, varSwap -- * Misc. , Style , EventId , TreeItem, treeItemInvalid, treeItemIsOk -- * Basic types -- ** Booleans , toCBool, fromCBool -- ** Colors , Color, rgb, colorRGB, colorRed, colorGreen, colorBlue, intFromColor, colorFromInt, colorIsOk, colorOk , black, darkgrey, dimgrey, mediumgrey, grey, lightgrey, white , red, green, blue , cyan, magenta, yellow -- *** System colors , SystemColor(..), colorSystem -- ** Points , Point, Point2(Point,pointX,pointY), point, pt, pointFromVec, pointFromSize, pointZero, pointNull , pointMove, pointMoveBySize, pointAdd, pointSub, pointScale -- ** Sizes , Size, Size2D(Size,sizeW,sizeH), sz, sizeFromPoint, sizeFromVec, sizeZero, sizeNull, sizeEncloses , sizeMin, sizeMax -- ** Vectors , Vector, Vector2(Vector,vecX,vecY), vector, vec, vecFromPoint, vecFromSize, vecZero, vecNull , vecNegate, vecOrtogonal, vecAdd, vecSub, vecScale, vecBetween, vecLength , vecLengthDouble -- ** Rectangles , Rect, Rect2D(Rect,rectLeft,rectTop,rectWidth,rectHeight) , rectTopLeft, rectTopRight, rectBottomLeft, rectBottomRight, rectBottom, rectRight , rect, rectBetween, rectFromSize, rectZero, rectNull, rectSize, rectIsEmpty , rectContains, rectMoveTo, rectFromPoint, rectCentralPoint, rectCentralRect, rectStretchTo , rectCentralPointDouble, rectCentralRectDouble , rectMove, rectOverlaps, rectsDiff, rectUnion, rectOverlap, rectUnions ) where import Data.List( (\\) ) import Graphics.UI.WXCore.WxcTypes import Graphics.UI.WXCore.WxcDefs import Graphics.UI.WXCore.WxcClasses( wxcSystemSettingsGetColour ) import System.IO.Unsafe( unsafePerformIO ) -- utility import Data.Array import Data.Bits import Data.Word import Control.Concurrent.STM import qualified Control.Exception as CE import qualified Control.Monad as M infixl 5 .+. infixl 5 .-. infix 5 # -- | Reverse application, i.e. @x # f@ = @f x@. -- Useful for an object oriented style of programming. -- -- > (frame # frameSetTitle) "hi" -- ( # ) :: obj -> (obj -> a) -> a object # method = method object {-------------------------------------------------------------------------------- Bitmasks --------------------------------------------------------------------------------} -- | Bitwise /or/ of two bit masks. (.+.) :: Bits a => a -> a -> a (.+.) i j = i .|. j -- | Unset certain bits in a bitmask. (.-.) :: Bits a => a -> a -> a (.-.) i j = i .&. complement j -- | Bitwise /or/ of a list of bit masks. bits :: (Num a, Bits a) => [a] -> a bits xs = foldr (.+.) 0 xs -- | (@bitsSet mask i@) tests if all bits in @mask@ are also set in @i@. bitsSet :: Bits a => a -> a -> Bool bitsSet mask i = (i .&. mask == mask) {-------------------------------------------------------------------------------- Id --------------------------------------------------------------------------------} {-# NOINLINE varTopId #-} varTopId :: Var Id varTopId = unsafePerformIO (varCreate (wxID_HIGHEST+1)) -- | When creating a new window you may specify 'idAny' to let wxWidgets -- assign an unused identifier to it automatically. Furthermore, it can be -- used in an event connection to handle events for any identifier. idAny :: Id idAny = -1 -- | Create a new unique identifier. idCreate :: IO Id idCreate = varUpdate varTopId (+1) {-------------------------------------------------------------------------------- Control --------------------------------------------------------------------------------} -- | Ignore the result of an 'IO' action. unitIO :: IO a -> IO () unitIO io = do io; return () -- | Perform an action when a test succeeds. when :: Bool -> IO () -> IO () when = M.when -- | Properly release resources, even in the event of an exception. bracket :: IO a -- ^ computation to run first (acquire resource) -> (a -> IO b) -- ^ computation to run last (release resource) -> (a -> IO c) -- ^ computation to run in-between (use resource) -> IO c bracket = CE.bracket -- | Specialized variant of 'bracket' where the return value is not required. bracket_ :: IO a -- ^ computation to run first (acquire resource) -> IO b -- ^ computation to run last (release resource) -> IO c -- ^ computation to run in-between (use resource) -> IO c bracket_ = CE.bracket_ -- | Run some computation afterwards, even if an exception occurs. finally :: IO a -- ^ computation to run first -> IO b -- ^ computation to run last (release resource) -> IO a finally = CE.finally -- | Run some computation afterwards, even if an exception occurs. Equals 'finally' but -- with the arguments swapped. finalize :: IO b -- ^ computation to run last (release resource) -> IO a -- ^ computation to run first -> IO a finalize last first = finally first last {-------------------------------------------------------------------------------- Variables --------------------------------------------------------------------------------} -- | A mutable variable. Use this instead of 'MVar's or 'IORef's to accomodate for -- future expansions with possible concurrency. type Var a = TVar a -- | Create a fresh mutable variable. varCreate :: a -> IO (Var a) varCreate x = newTVarIO x -- | Get the value of a mutable variable. varGet :: Var a -> IO a varGet v = atomically $ readTVar v -- | Set the value of a mutable variable. varSet :: Var a -> a -> IO () varSet v x = atomically $ writeTVar v x -- | Swap the value of a mutable variable. varSwap :: Var a -> a -> IO a varSwap v x = atomically $ do prev <- readTVar v writeTVar v x return prev -- | Update the value of a mutable variable and return the old value. varUpdate :: Var a -> (a -> a) -> IO a varUpdate v f = atomically $ do x <- readTVar v writeTVar v (f x) return x {----------------------------------------------------------------------------------------- Point -----------------------------------------------------------------------------------------} pointMove :: (Num a) => Vector2 a -> Point2 a -> Point2 a pointMove (Vector dx dy) (Point x y) = Point (x+dx) (y+dy) pointMoveBySize :: (Num a) => Point2 a -> Size2D a -> Point2 a pointMoveBySize (Point x y) (Size w h) = Point (x + w) (y + h) pointAdd :: (Num a) => Point2 a -> Point2 a -> Point2 a pointAdd (Point x1 y1) (Point x2 y2) = Point (x1+x2) (y1+y2) pointSub :: (Num a) => Point2 a -> Point2 a -> Point2 a pointSub (Point x1 y1) (Point x2 y2) = Point (x1-x2) (y1-y2) pointScale :: (Num a) => Point2 a -> a -> Point2 a pointScale (Point x y) v = Point (v*x) (v*y) instance (Num a, Ord a) => Ord (Point2 a) where compare (Point x1 y1) (Point x2 y2) = case compare y1 y2 of EQ -> compare x1 x2 neq -> neq instance Ix (Point2 Int) where range (Point x1 y1,Point x2 y2) = [Point x y | y <- [y1..y2], x <- [x1..x2]] inRange (Point x1 y1, Point x2 y2) (Point x y) = (x >= x1 && x <= x2 && y >= y1 && y <= y2) rangeSize (Point x1 y1, Point x2 y2) = let w = abs (x2 - x1) + 1 h = abs (y2 - y1) + 1 in w*h index bnd@(Point x1 y1, Point x2 y2) p@(Point x y) = if inRange bnd p then let w = abs (x2 - x1) + 1 in (y-y1)*w + x else error ("Point index out of bounds: " ++ show p ++ " not in " ++ show bnd) {----------------------------------------------------------------------------------------- Size -----------------------------------------------------------------------------------------} -- | Return the width. (see also 'sizeW'). sizeWidth :: (Num a) => Size2D a -> a sizeWidth (Size w h) = w -- | Return the height. (see also 'sizeH'). sizeHeight :: (Num a) => Size2D a -> a sizeHeight (Size w h) = h -- | Returns 'True' if the first size totally encloses the second argument. sizeEncloses :: (Num a, Ord a) => Size2D a -> Size2D a -> Bool sizeEncloses (Size w0 h0) (Size w1 h1) = (w0 >= w1) && (h0 >= h1) -- | The minimum of two sizes. sizeMin :: (Num a, Ord a) => Size2D a -> Size2D a -> Size2D a sizeMin (Size w0 h0) (Size w1 h1) = Size (min w0 w1) (min h0 h1) -- | The maximum of two sizes. sizeMax :: (Num a, Ord a) => Size2D a -> Size2D a -> Size2D a sizeMax (Size w0 h0) (Size w1 h1) = Size (max w0 w1) (max h0 h1) {----------------------------------------------------------------------------------------- Vector -----------------------------------------------------------------------------------------} vecNegate :: (Num a) => Vector2 a -> Vector2 a vecNegate (Vector x y) = Vector (-x) (-y) vecOrtogonal :: (Num a) => Vector2 a -> Vector2 a vecOrtogonal (Vector x y) = (Vector y (-x)) vecAdd :: (Num a) => Vector2 a -> Vector2 a -> Vector2 a vecAdd (Vector x1 y1) (Vector x2 y2) = Vector (x1+x2) (y1+y2) vecSub :: (Num a) => Vector2 a -> Vector2 a -> Vector2 a vecSub (Vector x1 y1) (Vector x2 y2) = Vector (x1-x2) (y1-y2) vecScale :: (Num a) => Vector2 a -> a -> Vector2 a vecScale (Vector x y) v = Vector (v*x) (v*y) vecBetween :: (Num a) => Point2 a -> Point2 a -> Vector2 a vecBetween (Point x1 y1) (Point x2 y2) = Vector (x2-x1) (y2-y1) vecLength :: Vector -> Double vecLength (Vector x y) = sqrt (fromIntegral (x*x + y*y)) vecLengthDouble :: Vector2 Double -> Double vecLengthDouble (Vector x y) = sqrt (x*x + y*y) {----------------------------------------------------------------------------------------- Rectangle -----------------------------------------------------------------------------------------} rectContains :: (Num a, Ord a) => Rect2D a -> Point2 a -> Bool rectContains (Rect l t w h) (Point x y) = (x >= l && x <= (l+w) && y >= t && y <= (t+h)) rectMoveTo :: (Num a) => Rect2D a -> Point2 a -> Rect2D a rectMoveTo r p = rect p (rectSize r) rectFromPoint :: (Num a) => Point2 a -> Rect2D a rectFromPoint (Point x y) = Rect x y x y rectCentralPoint :: Rect2D Int -> Point2 Int rectCentralPoint (Rect l t w h) = Point (l + div w 2) (t + div h 2) rectCentralRect :: Rect2D Int -> Size -> Rect2D Int rectCentralRect r@(Rect l t rw rh) (Size w h) = let c = rectCentralPoint r in Rect (pointX c - (w - div w 2)) (pointY c - (h - div h 2)) w h rectCentralPointDouble :: (Fractional a) => Rect2D a -> Point2 a rectCentralPointDouble (Rect l t w h) = Point (l + w/2) (t + h/2) rectCentralRectDouble :: (Fractional a) => Rect2D a -> Size2D a -> Rect2D a rectCentralRectDouble r@(Rect l t rw rh) (Size w h) = let c = rectCentralPointDouble r in Rect (pointX c - (w - w/2)) (pointY c - (h - h/2)) w h rectStretchTo :: (Num a) => Rect2D a -> Size2D a -> Rect2D a rectStretchTo (Rect l t _ _) (Size w h) = Rect l t w h rectMove :: (Num a) => Rect2D a -> Vector2 a -> Rect2D a rectMove (Rect x y w h) (Vector dx dy) = Rect (x+dx) (y+dy) w h rectOverlaps :: (Num a, Ord a) => Rect2D a -> Rect2D a -> Bool rectOverlaps (Rect x1 y1 w1 h1) (Rect x2 y2 w2 h2) = (x1+w1 >= x2 && x1 <= x2+w2) && (y1+h1 >= y2 && y1 <= y2+h2) -- | A list with rectangles that constitute the difference between two rectangles. rectsDiff :: (Num a, Ord a) => Rect2D a -> Rect2D a -> [Rect2D a] rectsDiff rect1 rect2 = subtractFittingRect rect1 (rectOverlap rect1 rect2) where -- subtractFittingRect r1 r2 subtracts r2 from r1 assuming that r2 fits inside r1 subtractFittingRect :: (Num a, Ord a) => Rect2D a -> Rect2D a -> [Rect2D a] subtractFittingRect r1 r2 = filter (not . rectIsEmpty) [ rectBetween (rectTopLeft r1) (rectTopRight r2) , rectBetween (pt (rectLeft r1) (rectTop r2)) (rectBottomLeft r2) , rectBetween (pt (rectLeft r1) (rectBottom r2)) (pt (rectRight r2) (rectBottom r1)) , rectBetween (rectTopRight r2) (rectBottomRight r1) ] rectUnion :: (Num a, Ord a) => Rect2D a -> Rect2D a -> Rect2D a rectUnion r1 r2 = rectBetween (pt (min (rectLeft r1) (rectLeft r2)) (min (rectTop r1) (rectTop r2))) (pt (max (rectRight r1) (rectRight r2)) (max (rectBottom r1) (rectBottom r2))) rectUnions :: (Num a, Ord a) => [Rect2D a] -> Rect2D a rectUnions [] = rectZero rectUnions (r:rs) = foldr rectUnion r rs -- | The intersection between two rectangles. rectOverlap :: (Num a, Ord a) => Rect2D a -> Rect2D a -> Rect2D a rectOverlap r1 r2 | rectOverlaps r1 r2 = rectBetween (pt (max (rectLeft r1) (rectLeft r2)) (max (rectTop r1) (rectTop r2))) (pt (min (rectRight r1) (rectRight r2)) (min (rectBottom r1) (rectBottom r2))) | otherwise = rectZero {----------------------------------------------------------------------------------------- Default colors. -----------------------------------------------------------------------------------------} black, darkgrey, dimgrey, mediumgrey, grey, lightgrey, white :: Color red, green, blue :: Color cyan, magenta, yellow :: Color black = colorRGB 0x00 0x00 0x00 darkgrey = colorRGB 0x2F 0x2F 0x2F dimgrey = colorRGB 0x54 0x54 0x54 mediumgrey= colorRGB 0x64 0x64 0x64 grey = colorRGB 0x80 0x80 0x80 lightgrey = colorRGB 0xC0 0xC0 0xC0 white = colorRGB 0xFF 0xFF 0xFF red = colorRGB 0xFF 0x00 0x00 green = colorRGB 0x00 0xFF 0x00 blue = colorRGB 0x00 0x00 0xFF yellow = colorRGB 0xFF 0xFF 0x00 magenta = colorRGB 0xFF 0x00 0xFF cyan = colorRGB 0x00 0xFF 0xFF {-------------------------------------------------------------------------- System colors --------------------------------------------------------------------------} -- | System Colors. data SystemColor = ColorScrollBar -- ^ The scrollbar grey area. | ColorBackground -- ^ The desktop colour. | ColorActiveCaption -- ^ Active window caption. | ColorInactiveCaption -- ^ Inactive window caption. | ColorMenu -- ^ Menu background. | ColorWindow -- ^ Window background. | ColorWindowFrame -- ^ Window frame. | ColorMenuText -- ^ Menu text. | ColorWindowText -- ^ Text in windows. | ColorCaptionText -- ^ Text in caption, size box and scrollbar arrow box. | ColorActiveBorder -- ^ Active window border. | ColorInactiveBorder -- ^ Inactive window border. | ColorAppWorkspace -- ^ Background colour MDI -- ^applications. | ColorHighlight -- ^ Item(s) selected in a control. | ColorHighlightText -- ^ Text of item(s) selected in a control. | ColorBtnFace -- ^ Face shading on push buttons. | ColorBtnShadow -- ^ Edge shading on push buttons. | ColorGrayText -- ^ Greyed (disabled) text. | ColorBtnText -- ^ Text on push buttons. | ColorInactiveCaptionText -- ^ Colour of text in active captions. | ColorBtnHighlight -- ^ Highlight colour for buttons (same as 3DHILIGHT). | Color3DDkShadow -- ^ Dark shadow for three-dimensional display elements. | Color3DLight -- ^ Light colour for three-dimensional display elements. | ColorInfoText -- ^ Text colour for tooltip controls. | ColorInfoBk -- ^ Background colour for tooltip controls. | ColorDesktop -- ^ Same as BACKGROUND. | Color3DFace -- ^ Same as BTNFACE. | Color3DShadow -- ^ Same as BTNSHADOW. | Color3DHighlight -- ^ Same as BTNHIGHLIGHT. | Color3DHilight -- ^ Same as BTNHIGHLIGHT. | ColorBtnHilight -- ^ Same as BTNHIGHLIGHT. instance Enum SystemColor where toEnum i = error "Graphics.UI.WXCore.Types.SytemColor.toEnum: can not convert integers to system colors." fromEnum systemColor = fromIntegral $ case systemColor of ColorScrollBar -> wxSYS_COLOUR_SCROLLBAR ColorBackground -> wxSYS_COLOUR_BACKGROUND ColorActiveCaption -> wxSYS_COLOUR_ACTIVECAPTION ColorInactiveCaption -> wxSYS_COLOUR_INACTIVECAPTION ColorMenu -> wxSYS_COLOUR_MENU ColorWindow -> wxSYS_COLOUR_WINDOW ColorWindowFrame -> wxSYS_COLOUR_WINDOWFRAME ColorMenuText -> wxSYS_COLOUR_MENUTEXT ColorWindowText -> wxSYS_COLOUR_WINDOWTEXT ColorCaptionText -> wxSYS_COLOUR_CAPTIONTEXT ColorActiveBorder -> wxSYS_COLOUR_ACTIVEBORDER ColorInactiveBorder -> wxSYS_COLOUR_INACTIVEBORDER ColorAppWorkspace -> wxSYS_COLOUR_APPWORKSPACE ColorHighlight -> wxSYS_COLOUR_HIGHLIGHT ColorHighlightText -> wxSYS_COLOUR_HIGHLIGHTTEXT ColorBtnFace -> wxSYS_COLOUR_BTNFACE ColorBtnShadow -> wxSYS_COLOUR_BTNSHADOW ColorGrayText -> wxSYS_COLOUR_GRAYTEXT ColorBtnText -> wxSYS_COLOUR_BTNTEXT ColorInactiveCaptionText -> wxSYS_COLOUR_INACTIVECAPTIONTEXT ColorBtnHighlight -> wxSYS_COLOUR_BTNHIGHLIGHT Color3DDkShadow -> wxSYS_COLOUR_3DDKSHADOW Color3DLight -> wxSYS_COLOUR_3DLIGHT ColorInfoText -> wxSYS_COLOUR_INFOTEXT ColorInfoBk -> wxSYS_COLOUR_INFOBK ColorDesktop -> wxSYS_COLOUR_DESKTOP Color3DFace -> wxSYS_COLOUR_3DFACE Color3DShadow -> wxSYS_COLOUR_3DSHADOW Color3DHighlight -> wxSYS_COLOUR_3DHIGHLIGHT Color3DHilight -> wxSYS_COLOUR_3DHILIGHT ColorBtnHilight -> wxSYS_COLOUR_BTNHILIGHT -- | Convert a system color to a color. colorSystem :: SystemColor -> Color colorSystem systemColor = unsafePerformIO $ wxcSystemSettingsGetColour (fromEnum systemColor)
ekmett/wxHaskell
wxcore/src/haskell/Graphics/UI/WXCore/Types.hs
lgpl-2.1
19,349
0
14
4,843
5,012
2,685
2,327
334
1
module Semantics.Stm (evalStm) where import Control.Exception import Data.Maybe (maybeToList) import Semantics.Bexp import Semantics.Variable import Semantics.Helpers import State.App import State.Config hiding (modifyTape) import qualified State.Config as Config (modifyTape, putStructMems) import State.Error import State.MachineClass import State.Output import State.Tape as Tape import Syntax.Tree -- Attempt to modify the tape, and throw if the tape does not exist. modifyTape :: (Monad m) => (Tape -> Tape) -> TapeExpr -> Config -> App m Config modifyTape f tapeExpr c = do (addr, c') <- tapePtr tapeExpr c tryMaybe (Config.modifyTape addr f c') UndefVar -- Evaluates moving the read-write head one cell to the left. evalLeft :: (Monad m) => TapeExpr -> Config -> App m Config evalLeft = modifyTape left -- Evaluates moving the read-write head one cell to the right. evalRight :: (Monad m) => TapeExpr -> Config -> App m Config evalRight = modifyTape right -- Evaluates writing to the tape. evalWrite :: (Monad m) => TapeExpr -> SymExpr -> Config -> App m Config evalWrite tapeExpr symExpr c = do (val, c') <- symVal symExpr c modifyTape (setSym val) tapeExpr c' -- Evaluates an if-else statement. evalIf :: (MonadOutput m) => Bexp -> Stm -> [(Bexp, Stm)] -> Maybe Stm -> Config -> App m Config evalIf bexp ifStm elseIfClauses elseStm = cond branches where branches = map (\(b, stm) -> (bexpVal b, block (evalStm stm))) allClauses allClauses = ((bexp, ifStm):elseIfClauses) ++ (maybeToList elseClause) elseClause = fmap (\stm -> (TRUE, stm)) elseStm -- Evaluates a while loop. evalWhile :: (MonadOutput m) => Bexp -> Stm -> Config -> App m Config evalWhile b body = fix f where f loop = cond [(bexpVal b, evalLoop)] where evalLoop c = block (evalStm body) c >>= loop -- Evaluates a variable declaration. evalVarDecl :: (Monad m) => VarName -> AnyValExpr -> Config -> App m Config evalVarDecl name anyExpr c = do (v, c') <- anyVal anyExpr c return (putVar name v c') -- Evaluates a function declaration. evalFuncDecl :: (Monad m) => FuncName -> [FuncDeclArg] -> Stm -> Config -> App m Config evalFuncDecl name args body config = return (putFunc name args body config) -- Checks that the number of arguments to a function is the same as the number -- of arguments the function declaration specified. checkNumArgs :: (Monad m) => FuncName -> [FuncDeclArg] -> [FuncCallArg] -> Config -> App m Config checkNumArgs name ds cs config | (length ds) == (length cs) = return config | otherwise = throw err where err = WrongNumArgs name ds cs -- Binds function arguments to values supplied to the function. bindFuncArg :: (Monad m) => (FuncDeclArg, FuncCallArg) -> App m Config -> App m Config bindFuncArg ((name, _), valExpr) app = app >>= evalVarDecl name valExpr -- Evaluates the body of a function, after adding any arguments to the variable -- environment. The variable and function environments are reset after executing -- the body. evalFuncBody :: (MonadOutput m) => FuncName -> [FuncDeclArg] -> [FuncCallArg] -> Stm -> Config -> App m Config evalFuncBody name ds cs body config = do -- Check the number of arguments to the function is the correct. let app = checkNumArgs name ds cs config let zippedArgs = zip ds cs -- A config where the arguments have been added to the environment. addedVarsConfig <- foldr bindFuncArg app zippedArgs newConfig <- block (evalStm body) addedVarsConfig oldConfig <- app -- Reset the environment so variables declared as function arguments do not -- 'leak' out. return (revertEnv oldConfig newConfig) -- Evaluates a function call. evalCall :: (MonadOutput m) => FuncName -> [FuncCallArg] -> Config -> App m Config evalCall name args config = do let fMaybe = getFunc name config maybe err eval fMaybe where err = throw (UndefFunc name) eval (argNames, body) = evalFuncBody name argNames args body config -- Evaluates a structure declaration, e.g. struct S { x:Tape } evalStructDecl :: (Monad m) => StructName -> [StructMemberVar] -> Config -> App m Config evalStructDecl name mems c = return (Config.putStructMems name memNames c) where memNames = fmap fst mems -- Evaluates the composition of two statements. evalComp :: (MonadOutput m) => Stm -> Stm -> Config -> App m Config evalComp stm1 stm2 config = (evalStm stm1 config) >>= (evalStm stm2) -- Evaluates printing a symbol. evalPrintRead :: (MonadOutput m) => SymExpr -> Config -> App m Config evalPrintRead symExpr c = do (sym, c') <- symVal symExpr c output' [sym] c' -- Evalutes printing a symbol and a newline. evalPrintReadLn :: (MonadOutput m) => Maybe SymExpr -> Config -> App m Config evalPrintReadLn Nothing c = output' ['\n'] c evalPrintReadLn (Just symExpr) c = do (sym, c') <- symVal symExpr c output' (sym:"\n") c' -- Evalutes debug printing the contents of a tape. evalDebugPrintTape :: (MonadOutput m) => TapeExpr -> Config -> App m Config evalDebugPrintTape tapeExpr c1 = do (addr, c2) <- tapePtr tapeExpr c1 (TapeRef tape) <- tryMaybe (derefPtr addr c2) UndefVar output' (show tape ++ "\n") c2 -- Evalautes a statement in a configuration of a Turing machine. evalStm :: (MonadOutput m) => Stm -> Config -> App m Config evalStm (MoveLeft tapeExpr) = evalLeft tapeExpr evalStm (MoveRight tapeExpr) = evalRight tapeExpr evalStm (Write tapeExpr sym) = evalWrite tapeExpr sym evalStm (Accept) = const accept evalStm (Reject) = const reject evalStm (If b stm elseIf elseStm) = evalIf b stm elseIf elseStm evalStm (While b stm) = evalWhile b stm evalStm (VarDecl name expr) = evalVarDecl name expr evalStm (FuncDecl name args body) = evalFuncDecl name args body evalStm (Call name args) = evalCall name args evalStm (StructDecl structName mems) = evalStructDecl structName mems evalStm (Comp stm1 stm2) = evalComp stm1 stm2 evalStm (Print symExpr) = evalPrintRead symExpr evalStm (PrintLn symExpr) = evalPrintReadLn symExpr evalStm (DebugPrintTape tapeExpr) = evalDebugPrintTape tapeExpr
BakerSmithA/Turing
src/Semantics/Stm.hs
bsd-3-clause
6,290
0
13
1,358
1,910
978
932
96
1
module Foreign.HaPy.Internal ( sizeOfList, peekList, pokeList, copyList ) where import Foreign.C ( CInt ) import Foreign.Marshal.Array ( pokeArray, peekArray ) import Foreign.Marshal.Alloc ( mallocBytes ) import Foreign.Storable ( Storable(..) ) import Foreign.Ptr ( Ptr, plusPtr, castPtr, alignPtr ) cInt :: CInt cInt = undefined lenPtr :: Storable a => Ptr [a] -> Ptr CInt lenPtr = castPtr arrPtr :: Storable a => Ptr [a] -> Ptr a arrPtr ptr = castPtr $ (ptr `plusPtr` sizeOf cInt) `alignPtr` alignment (ptrElem ptr) where ptrElem :: Ptr [a] -> a ptrElem = undefined sizeOfList :: Storable a => [a] -> Int sizeOfList xs = alignedIntSize + length xs * sizeOf (head xs) where alignedIntSize = max (sizeOf cInt) (alignment $ head xs) peekList :: Storable a => Ptr [a] -> IO [a] peekList ptr = do len <- peek $ lenPtr ptr peekArray (fromIntegral len) $ arrPtr ptr pokeList :: Storable a => Ptr [a] -> [a] -> IO () pokeList ptr xs = do poke (lenPtr ptr) (fromIntegral $ length xs) pokeArray (arrPtr ptr) xs copyList :: Storable a => [a] -> IO (Ptr [a]) copyList xs = do ptr <- mallocBytes $ sizeOfList xs pokeList ptr xs return ptr
SamuelMarks/haskell-python-talk
HaPy-haskell/Foreign/HaPy/Internal.hs
mit
1,171
0
10
240
508
262
246
34
1
module Language.Zahl where -- -- $Id$ import Random zahl :: Int -> IO String -- ein Integer dieser Länge zahl 0 = return "0" zahl l = do c <- randomRIO ( '1' , '9' ) cs <- sequence $ replicate l $ randomRIO ( '0', '9' ) return $ c : cs
Erdwolf/autotool-bonn
src/Language/Zahl.hs
gpl-2.0
256
0
10
72
96
49
47
8
1
{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} -- | -- Copyright : (c) 2010-2012 Benedikt Schmidt & Simon Meier -- License : GPL v3 (see LICENSE) -- -- Maintainer : Simon Meier <[email protected]> -- Portability : GHC only -- -- Common types for our constraint solver. They must be declared jointly -- because there is a recursive dependency between goals, proof contexts, and -- case distinctions. -- Needed to move common types to System, now this modul is just passing them through. module Theory.Constraint.Solver.Types ( -- module Logic.Connectives -- module Theory.Constraint.System -- , module Theory.Text.Pretty -- , module Theory.Model ) where -- import Prelude hiding (id, (.)) -- -- import Data.Binary -- import Data.DeriveTH -- import Data.Label hiding (get) -- import qualified Data.Label as L -- import Data.Monoid (Monoid(..)) -- import qualified Data.Set as S -- -- import Control.Basics -- import Control.Category -- import Control.DeepSeq -- import Logic.Connectives -- import Theory.Constraint.System -- import Theory.Text.Pretty -- import Theory.Model
ekr/tamarin-prover
lib/theory/src/Theory/Constraint/Solver/Types.hs
gpl-3.0
1,425
0
3
403
47
44
3
6
0
{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module DataFamilies.Instances () where import Prelude.Compat import Data.Aeson.TH import Data.Aeson.Types (FromJSON(..)) import DataFamilies.Types import Test.QuickCheck (Arbitrary(..), elements, oneof) instance (Arbitrary a) => Arbitrary (Approx a) where arbitrary = Approx <$> arbitrary instance Arbitrary (Nullary Int) where arbitrary = elements [C1, C2, C3] instance Arbitrary a => Arbitrary (SomeType c () a) where arbitrary = oneof [ pure Nullary , Unary <$> arbitrary , Product <$> arbitrary <*> arbitrary <*> arbitrary , Record <$> arbitrary <*> arbitrary <*> arbitrary , List <$> arbitrary ] instance Arbitrary (GADT String) where arbitrary = GADT <$> arbitrary deriveJSON defaultOptions 'C1 deriveJSON defaultOptions 'Nullary deriveJSON defaultOptions 'Approx deriveToJSON defaultOptions 'GADT -- We must write the FromJSON instance head ourselves -- due to the refined GADT return type instance FromJSON (GADT String) where parseJSON = $(mkParseJSON defaultOptions 'GADT)
dmjio/aeson
tests/DataFamilies/Instances.hs
bsd-3-clause
1,323
0
10
302
304
168
136
30
0
data Nat = S Nat | Z deriving (Eq, Show)
osa1/chsc
examples/toys/Generalisation.hs
bsd-3-clause
50
0
6
19
24
13
11
2
0
foo = maybe Bar{..} id
bitemyapp/apply-refact
tests/examples/Default113.hs
bsd-3-clause
22
0
6
4
16
8
8
-1
-1
{-# LANGUAGE CPP #-} module Main where import TestData import Control.Monad import Data.Char (isLetter) import qualified Data.IntMap as IMap import Data.Monoid ((<>)) import Data.Proxy import Data.Typeable import Options.Applicative import System.Directory import System.Exit import System.FilePath ((</>)) import System.Info import System.IO import System.Process import Test.Tasty import Test.Tasty.Golden import Test.Tasty.Ingredients.Rerun import Test.Tasty.Options import Test.Tasty.Runners --------------------------------------------------------------------- [ Config ] type Flags = [String] -- Add arguments to calls of idris executable idrisFlags :: Flags idrisFlags = [] testDirectory :: String testDirectory = "test" -------------------------------------------------------------------- [ Options ] -- The `--node` option makes idris use the node code generator -- As a consequence, incompatible tests are removed newtype NodeOpt = NodeOpt Bool deriving (Eq, Ord, Typeable) nodeArg = "node" nodeHelp = "Performs the tests with the node code generator" instance IsOption NodeOpt where defaultValue = NodeOpt False parseValue = fmap NodeOpt . safeRead optionName = return nodeArg optionHelp = return nodeHelp optionCLParser = NodeOpt <$> switch (long nodeArg <> help nodeHelp) ingredients :: [Ingredient] ingredients = defaultIngredients ++ [rerunningTests [consoleTestReporter], includingOptions [Option (Proxy :: Proxy NodeOpt)] ] ----------------------------------------------------------------------- [ Core ] -- Compare a given file contents against the golden file contents -- A ripoff of goldenVsFile from Tasty.Golden test :: String -> String -> IO () -> TestTree test testName path = goldenVsFileDiff testName diff ref output where ref = path </> "expected" output = path </> "output" diff ref new | os == "openbsd" = ["diff", "-u", new, ref] | otherwise = ["diff", "--strip-trailing-cr", "-u", new, ref] -- Should always output a 3-charater string from a postive Int indexToString :: Int -> String indexToString index = let str = show index in replicate (3 - length str) '0' ++ str -- Turns the collection of TestFamily into actual tests usable by Tasty mkGoldenTests :: [TestFamily] -> Flags -> TestTree mkGoldenTests testFamilies flags = testGroup "Regression and feature tests" (fmap mkTestFamily testFamilies) where mkTestFamily (TestFamily id name tests) = testGroup name (fmap (mkTest id) (IMap.keys tests)) mkTest id index = let testname = id ++ indexToString index path = testDirectory </> testname in test testname path (runTest path flags) -- Runs a test script -- "bash" needed because Haskell has cmd as the default shell on windows, and -- we also want to run the process with another current directory, so we get -- this thing. runTest :: String -> Flags -> IO () runTest path flags = do let run = (proc "bash" ("run" : flags)) {cwd = Just path} (_, output, error_out) <- readCreateProcessWithExitCode run "" writeFile (path </> "output") (normalise output) when (error_out /= "") $ hPutStrLn stderr ("\nError: " ++ path ++ "\n" ++ error_out) where -- Normalise paths e.g. '.\foo.idr' to './foo.idr'. -- Also embedded paths e.g. ".\\Prelude\\List.idr" to "./Prelude/List.idr". normalise ('.' : '\\' : c : xs) | isLetter c = '.' : '/' : c : normalise xs normalise ('\\':'\\':xs) = '/' : normalise xs normalise (x : xs) = x : normalise xs normalise [] = [] main :: IO () main = do nodePath <- findExecutable "node" nodejsPath <- findExecutable "nodejs" let node = nodePath <|> nodejsPath case node of Nothing -> do putStrLn "For running the test suite against Node, node must be installed." exitFailure Just _ -> do defaultMainWithIngredients ingredients $ askOption $ \(NodeOpt node) -> let (codegen, flags) = if node then (JS, ["--codegen", "node"]) else (C , []) in mkGoldenTests (testFamiliesForCodegen codegen) (flags ++ idrisFlags)
uuhan/Idris-dev
test/TestRun.hs
bsd-3-clause
4,250
0
20
946
1,041
554
487
84
4
{-# LANGUAGE RoleAnnotations, PolyKinds #-} module Roles1 where import Data.Kind (Type) data T1 a = K1 a data T2 a = K2 a data T3 (a :: k) = K3 data T4 (a :: Type -> Type) b = K4 (a b) data T5 a = K5 a data T6 a = K6 data T7 a b = K7 b type role T1 nominal type role T2 representational type role T3 phantom type role T4 nominal _ type role T5 _
sdiehl/ghc
testsuite/tests/roles/should_compile/Roles1.hs
bsd-3-clause
351
0
8
86
137
86
51
-1
-1
{-# OPTIONS_GHC -fno-warn-redundant-constraints #-} {-# LANGUAGE RankNTypes, LiberalTypeSynonyms #-} -- This test checks that deep skolemisation and deep -- instanatiation work right. A buggy prototype -- of GHC 7.0, where the type checker generated wrong -- code, sent applyTypeToArgs into a loop. module Twins where import Data.Data type GenericQ r = forall a. Data a => a -> r type GenericM m = forall a. Data a => a -> m a gzip :: GenericQ (GenericM Maybe) -> GenericQ (GenericM Maybe) gzip f x y = f x y `orElse` if toConstr x == toConstr y then gzipWithM (gzip f) x y else Nothing gzipWithM :: Monad m => GenericQ (GenericM m) -> GenericQ (GenericM m) gzipWithM _ = error "urk" orElse :: Maybe a -> Maybe a -> Maybe a orElse = error "urk"
oldmanmike/ghc
testsuite/tests/typecheck/should_compile/twins.hs
bsd-3-clause
772
0
9
162
220
114
106
17
2
{-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-missing-signatures #-} {-# LANGUAGE CPP #-} {-# LINE 13 "examples/ghc/ghc/compiler/cmm/CmmLex.x" #-} -- See Note [Warnings in code generated by Alex] in compiler/parser/Lexer.x {-# OPTIONS_GHC -fno-warn-unused-matches #-} {-# OPTIONS_GHC -fno-warn-unused-binds #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# OPTIONS_GHC -fno-warn-tabs #-} {-# OPTIONS_GHC -fno-warn-missing-signatures #-} module CmmLex ( CmmToken(..), cmmlex, ) where import GhcPrelude import CmmExpr import Lexer import CmmMonad import SrcLoc import UniqFM import StringBuffer import FastString import Ctype import Util --import TRACE import Data.Word import Data.Char #if __GLASGOW_HASKELL__ >= 603 #include "ghcconfig.h" #elif defined(__GLASGOW_HASKELL__) #include "config.h" #endif #if __GLASGOW_HASKELL__ >= 503 import Data.Array import Data.Array.Base (unsafeAt) #else import Array #endif alex_tab_size :: Int alex_tab_size = 8 alex_base :: Array Int Int alex_base = listArray (0 :: Int, 189) [ 1 , 127 , 120 , 194 , -100 , 165 , 193 , 222 , 236 , -94 , 322 , 450 , 705 , 680 , -103 , -98 , 808 , 936 , 1064 , 1192 , 1320 , -95 , 1448 , 1576 , -88 , -99 , 0 , 1689 , 0 , 1802 , 0 , 1915 , 0 , 1980 , 0 , 2093 , 0 , 2206 , 0 , 2271 , 0 , 2336 , 2592 , 2686 , 2615 , 0 , 0 , 2680 , 0 , 2745 , 3001 , 2937 , 0 , -93 , 3193 , 3129 , 0 , 3384 , 3597 , 3385 , 3842 , 3533 , 0 , 3970 , 3906 , 0 , 4152 , 4398 , -144 , 4526 , 3383 , 4773 , 0 , 0 , -90 , 5019 , 5265 , 250 , 0 , 5511 , 5757 , 6003 , 6249 , 6495 , 6741 , 6987 , 7233 , 7479 , 7725 , 0 , -42 , -41 , 0 , -101 , -17 , -36 , -35 , -30 , 7980 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 8112 , 8244 , 8376 , 8508 , 8640 , 8772 , 8904 , 9036 , 9168 , 9300 , 9432 , 9564 , 9696 , 9828 , 9960 , 10092 , 10224 , 10356 , 10488 , 10620 , 10752 , 10884 , 11016 , 11148 , 11280 , 11412 , 11544 , 11676 , 11808 , 11940 , 12072 , 12204 , 12336 , 12468 , 12600 , 12732 , 12864 , 12996 , 13128 , 13260 , 13392 , 13524 , 13656 , 13788 , 13920 , 14052 , 14184 , 14316 , 14448 , 14580 , 14712 , 14844 , 14976 , 15108 , 15240 , 15372 , 15504 , 15636 , 15768 , 15900 , 16032 , 16164 , 16296 , 16428 , 16560 , 16692 , 16824 , 16956 , 17088 , 17220 , 17352 , 17484 , 17616 , 17748 , 17880 , 4162 , 4408 , 17970 , 4172 , 4418 , 728 , 0 ] alex_table :: Array Int Int alex_table = listArray (0 :: Int, 18225) [ 0 , 73 , 184 , 67 , 159 , 159 , 9 , 53 , 14 , 21 , 70 , 89 , 70 , 70 , 70 , 24 , 70 , 4 , 15 , 104 , 105 , 106 , 25 , 107 , 101 , 103 , 102 , 100 , 99 , 0 , 0 , 0 , 0 , 70 , 91 , 58 , 74 , 159 , 92 , 94 , 0 , 92 , 92 , 92 , 92 , 92 , 92 , 182 , 92 , 185 , 184 , 184 , 184 , 184 , 184 , 184 , 184 , 184 , 184 , 97 , 92 , 95 , 90 , 96 , 0 , 159 , 159 , 154 , 145 , 127 , 159 , 126 , 159 , 180 , 159 , 159 , 159 , 128 , 151 , 159 , 159 , 124 , 159 , 125 , 181 , 159 , 160 , 159 , 159 , 159 , 159 , 159 , 92 , 0 , 92 , 92 , 159 , 92 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 92 , 93 , 92 , 92 , 77 , 70 , 0 , 70 , 70 , 70 , 0 , 0 , 70 , 0 , 70 , 70 , 70 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 70 , 0 , 66 , 74 , 0 , 0 , 0 , 70 , 0 , 0 , 74 , 0 , 0 , 0 , 186 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 77 , 77 , 77 , 77 , 77 , 77 , 77 , 77 , 77 , 77 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 188 , 68 , 59 , 0 , 0 , 0 , 0 , 0 , 0 , 71 , -1 , 71 , 71 , 71 , 0 , 0 , 0 , 0 , 0 , 186 , 186 , 186 , 186 , 186 , 186 , 186 , 186 , 186 , 186 , 187 , 0 , 0 , 71 , 0 , 0 , 76 , 186 , 186 , 186 , 186 , 186 , 186 , 8 , 188 , 8 , 0 , 0 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 77 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 186 , 186 , 186 , 186 , 186 , 186 , 0 , 0 , 187 , 187 , 187 , 187 , 187 , 187 , 187 , 187 , 187 , 187 , 0 , 0 , 0 , 0 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 0 , 0 , 0 , 0 , 77 , 77 , 77 , 77 , 77 , 77 , 77 , 77 , 77 , 77 , 0 , 0 , 0 , 0 , 0 , 0 , 68 , 0 , 0 , 0 , 0 , 0 , 0 , 68 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 69 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 63 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 57 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 188 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 57 , 57 , 57 , 57 , 57 , 57 , 57 , 57 , 57 , 57 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 57 , 57 , 57 , 57 , 57 , 57 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 188 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 57 , 57 , 57 , 57 , 57 , 57 , 54 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 50 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 10 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 42 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 13 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 16 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 19 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 33 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 39 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 41 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 44 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 47 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 49 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 51 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 55 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 58 , 0 , 0 , 0 , 0 , 58 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 58 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 58 , 0 , 0 , 0 , 0 , 58 , 58 , 0 , 0 , 0 , 58 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 58 , 0 , 0 , 0 , 58 , 0 , 58 , 0 , 0 , 0 , 12 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 61 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 64 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 58 , 0 , 0 , 0 , 0 , 0 , 0 , 70 , 0 , 70 , 70 , 70 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 70 , 58 , 58 , 189 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 43 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 68 , 42 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 44 , 19 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 33 , 23 , 26 , 26 , 26 , 27 , 58 , 58 , 189 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 43 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , 58 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 42 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 45 , 44 , 19 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 32 , 33 , 23 , 26 , 26 , 26 , 27 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 184 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 186 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 78 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 0 , 183 , 183 , 183 , 183 , 183 , 183 , 183 , 183 , 184 , 184 , 186 , 186 , 186 , 186 , 186 , 186 , 186 , 186 , 186 , 186 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 186 , 186 , 186 , 186 , 186 , 186 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 186 , 186 , 186 , 186 , 186 , 186 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 50 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 52 , 51 , 16 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 38 , 39 , 22 , 28 , 28 , 28 , 29 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 72 , 184 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 187 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 0 , 184 , 184 , 184 , 184 , 184 , 184 , 184 , 184 , 184 , 184 , 187 , 187 , 187 , 187 , 187 , 187 , 187 , 187 , 187 , 187 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 54 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 56 , 55 , 13 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 40 , 41 , 20 , 30 , 30 , 30 , 31 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 71 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 71 , -1 , 71 , 71 , 71 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 71 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 69 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 82 , 0 , 0 , 0 , 86 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 75 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 88 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 80 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 87 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 81 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 83 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 84 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 79 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 60 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 62 , 61 , 11 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 46 , 47 , 18 , 34 , 34 , 34 , 35 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 72 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 63 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 65 , 64 , 10 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 48 , 49 , 17 , 36 , 36 , 36 , 37 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 108 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 108 , 108 , 108 , 108 , 108 , 108 , 108 , 108 , 108 , 108 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 109 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 109 , 109 , 109 , 109 , 109 , 109 , 109 , 109 , 109 , 109 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 110 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 110 , 110 , 110 , 110 , 110 , 110 , 110 , 110 , 110 , 110 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 111 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 111 , 111 , 111 , 111 , 111 , 111 , 111 , 111 , 111 , 111 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 112 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 112 , 112 , 112 , 112 , 112 , 112 , 112 , 112 , 112 , 112 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 137 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 171 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 138 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 108 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 108 , 108 , 108 , 108 , 108 , 108 , 108 , 108 , 108 , 108 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 109 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 109 , 109 , 109 , 109 , 109 , 109 , 109 , 109 , 109 , 109 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 110 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 110 , 110 , 110 , 110 , 110 , 110 , 110 , 110 , 110 , 110 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 111 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 111 , 111 , 111 , 111 , 111 , 111 , 111 , 111 , 111 , 111 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 112 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 112 , 112 , 112 , 112 , 112 , 112 , 112 , 112 , 112 , 112 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 114 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 116 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 117 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 118 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 119 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 120 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 121 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 123 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 129 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 130 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 131 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 132 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 134 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 135 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 179 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 136 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 139 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 164 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 178 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 146 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 175 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 174 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 148 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 149 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 169 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 168 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 150 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 167 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 165 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 161 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 157 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 158 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 162 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 163 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 156 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 166 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 155 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 152 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 170 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 147 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 172 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 173 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 176 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 177 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 144 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 143 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 142 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 141 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 153 , 159 , 159 , 159 , 159 , 159 , 140 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 133 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 122 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 115 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 113 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 98 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 59 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 184 , 0 , 0 , 0 , 159 , 0 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 159 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 0 , 183 , 183 , 183 , 183 , 183 , 183 , 183 , 183 , 184 , 184 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 59 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] alex_check :: Array Int Int alex_check = listArray (0 :: Int, 18225) [ -1 , 101 , 1 , 97 , 3 , 4 , 109 , 105 , 103 , 97 , 9 , 10 , 11 , 12 , 13 , 114 , 160 , 110 , 108 , 61 , 61 , 38 , 112 , 124 , 60 , 61 , 61 , 62 , 58 , -1 , -1 , -1 , -1 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , -1 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , -1 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , -1 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 1 , 9 , -1 , 11 , 12 , 13 , -1 , -1 , 9 , -1 , 11 , 12 , 13 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 32 , -1 , 34 , 35 , -1 , -1 , -1 , 32 , -1 , -1 , 35 , -1 , -1 , -1 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , 194 , 195 , -1 , -1 , -1 , -1 , -1 , -1 , 9 , 10 , 11 , 12 , 13 , -1 , -1 , -1 , -1 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 1 , -1 , -1 , 32 , -1 , -1 , 35 , 65 , 66 , 67 , 68 , 69 , 70 , 43 , 1 , 45 , -1 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , -1 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , -1 , 194 , -1 , -1 , -1 , -1 , -1 , -1 , 194 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 65 , 66 , 67 , 68 , 69 , 70 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 34 , -1 , -1 , -1 , -1 , 39 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 63 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 92 , -1 , -1 , -1 , -1 , 97 , 98 , -1 , -1 , -1 , 102 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 110 , -1 , -1 , -1 , 114 , -1 , 116 , -1 , -1 , -1 , 120 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , 9 , -1 , 11 , 12 , 13 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 32 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , -1 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , -1 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 194 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , -1 , -1 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 , 127 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 34 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , 69 , -1 , -1 , -1 , -1 , -1 , 65 , 66 , 67 , 68 , 69 , 70 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 101 , -1 , -1 , -1 , -1 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , 69 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 69 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 101 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 101 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 9 , 10 , 11 , 12 , 13 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 32 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 108 , -1 , -1 , -1 , 112 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 101 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 97 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 109 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 105 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 103 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 97 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 114 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 110 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 10 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 128 , 129 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 , 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 , 184 , 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 , 209 , 210 , 211 , 212 , 213 , 214 , 215 , 216 , 217 , 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 , 234 , 235 , 236 , 237 , 238 , 239 , 240 , 241 , 242 , 243 , 244 , 245 , 246 , 247 , 248 , 249 , 250 , 251 , 252 , 253 , 254 , 255 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , -1 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , -1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 1 , -1 , 3 , 4 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 36 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , 195 , 64 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 1 , -1 , -1 , -1 , 95 , -1 , 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 , 122 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 46 , -1 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 69 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 88 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 101 , -1 , -1 , -1 , 195 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 120 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ] alex_deflt :: Array Int Int alex_deflt = listArray (0 :: Int, 189) [ -1 , -1 , -1 , 85 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , 32 , 32 , 38 , 38 , 40 , 40 , 45 , 45 , 46 , 46 , 48 , 48 , 52 , 52 , 56 , 56 , 58 , -1 , 58 , 58 , 62 , 62 , 65 , 65 , 66 , 66 , 66 , -1 , 67 , 67 , 67 , -1 , -1 , -1 , 85 , 85 , 85 , 88 , 88 , 88 , 66 , 67 , -1 , -1 , -1 , 85 , -1 , -1 , -1 , 85 , 85 , -1 , -1 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 85 , 88 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ] alex_accept = listArray (0 :: Int, 189) [ AlexAccNone , AlexAccNone , AlexAccNone , AlexAcc 118 , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccNone , AlexAccSkip , AlexAccSkip , AlexAccSkipPred (alexPrevCharMatches(\c -> c >= '\n' && c <= '\n' || False))(AlexAccNone) , AlexAccPred 117 (alexPrevCharMatches(\c -> c >= '\n' && c <= '\n' || False))(AlexAccNone) , AlexAccPred 116 (alexPrevCharMatches(\c -> c >= '\n' && c <= '\n' || False))(AlexAccNone) , AlexAccPred 115 (alexPrevCharMatches(\c -> c >= '\n' && c <= '\n' || False))(AlexAcc 114) , AlexAccPred 113 (alexPrevCharMatches(\c -> c >= '\n' && c <= '\n' || False))(AlexAcc 112) , AlexAcc 111 , AlexAcc 110 , AlexAcc 109 , AlexAcc 108 , AlexAcc 107 , AlexAcc 106 , AlexAcc 105 , AlexAcc 104 , AlexAcc 103 , AlexAcc 102 , AlexAcc 101 , AlexAcc 100 , AlexAccSkip , AlexAcc 99 , AlexAcc 98 , AlexAcc 97 , AlexAcc 96 , AlexAcc 95 , AlexAcc 94 , AlexAcc 93 , AlexAcc 92 , AlexAcc 91 , AlexAcc 90 , AlexAcc 89 , AlexAcc 88 , AlexAcc 87 , AlexAcc 86 , AlexAcc 85 , AlexAcc 84 , AlexAcc 83 , AlexAcc 82 , AlexAcc 81 , AlexAcc 80 , AlexAcc 79 , AlexAcc 78 , AlexAcc 77 , AlexAcc 76 , AlexAcc 75 , AlexAcc 74 , AlexAcc 73 , AlexAcc 72 , AlexAcc 71 , AlexAcc 70 , AlexAcc 69 , AlexAcc 68 , AlexAcc 67 , AlexAcc 66 , AlexAcc 65 , AlexAcc 64 , AlexAcc 63 , AlexAcc 62 , AlexAcc 61 , AlexAcc 60 , AlexAcc 59 , AlexAcc 58 , AlexAcc 57 , AlexAcc 56 , AlexAcc 55 , AlexAcc 54 , AlexAcc 53 , AlexAcc 52 , AlexAcc 51 , AlexAcc 50 , AlexAcc 49 , AlexAcc 48 , AlexAcc 47 , AlexAcc 46 , AlexAcc 45 , AlexAcc 44 , AlexAcc 43 , AlexAcc 42 , AlexAcc 41 , AlexAcc 40 , AlexAcc 39 , AlexAcc 38 , AlexAcc 37 , AlexAcc 36 , AlexAcc 35 , AlexAcc 34 , AlexAcc 33 , AlexAcc 32 , AlexAcc 31 , AlexAcc 30 , AlexAcc 29 , AlexAcc 28 , AlexAcc 27 , AlexAcc 26 , AlexAcc 25 , AlexAcc 24 , AlexAcc 23 , AlexAcc 22 , AlexAcc 21 , AlexAcc 20 , AlexAcc 19 , AlexAcc 18 , AlexAcc 17 , AlexAcc 16 , AlexAcc 15 , AlexAcc 14 , AlexAcc 13 , AlexAcc 12 , AlexAcc 11 , AlexAcc 10 , AlexAcc 9 , AlexAcc 8 , AlexAcc 7 , AlexAcc 6 , AlexAcc 5 , AlexAcc 4 , AlexAcc 3 , AlexAcc 2 , AlexAcc 1 , AlexAcc 0 ] alex_actions = array (0 :: Int, 119) [ (118,alex_action_5) , (117,alex_action_2) , (116,alex_action_2) , (115,alex_action_2) , (114,alex_action_5) , (113,alex_action_2) , (112,alex_action_5) , (111,alex_action_3) , (110,alex_action_4) , (109,alex_action_5) , (108,alex_action_5) , (107,alex_action_5) , (106,alex_action_5) , (105,alex_action_5) , (104,alex_action_5) , (103,alex_action_5) , (102,alex_action_5) , (101,alex_action_5) , (100,alex_action_5) , (99,alex_action_7) , (98,alex_action_7) , (97,alex_action_7) , (96,alex_action_7) , (95,alex_action_7) , (94,alex_action_7) , (93,alex_action_7) , (92,alex_action_7) , (91,alex_action_8) , (90,alex_action_9) , (89,alex_action_10) , (88,alex_action_11) , (87,alex_action_12) , (86,alex_action_13) , (85,alex_action_14) , (84,alex_action_15) , (83,alex_action_16) , (82,alex_action_17) , (81,alex_action_18) , (80,alex_action_19) , (79,alex_action_20) , (78,alex_action_21) , (77,alex_action_22) , (76,alex_action_23) , (75,alex_action_24) , (74,alex_action_25) , (73,alex_action_26) , (72,alex_action_27) , (71,alex_action_28) , (70,alex_action_29) , (69,alex_action_30) , (68,alex_action_31) , (67,alex_action_32) , (66,alex_action_33) , (65,alex_action_34) , (64,alex_action_34) , (63,alex_action_34) , (62,alex_action_34) , (61,alex_action_34) , (60,alex_action_34) , (59,alex_action_34) , (58,alex_action_34) , (57,alex_action_34) , (56,alex_action_34) , (55,alex_action_34) , (54,alex_action_34) , (53,alex_action_34) , (52,alex_action_34) , (51,alex_action_34) , (50,alex_action_34) , (49,alex_action_34) , (48,alex_action_34) , (47,alex_action_34) , (46,alex_action_34) , (45,alex_action_34) , (44,alex_action_34) , (43,alex_action_34) , (42,alex_action_34) , (41,alex_action_34) , (40,alex_action_34) , (39,alex_action_34) , (38,alex_action_34) , (37,alex_action_34) , (36,alex_action_34) , (35,alex_action_34) , (34,alex_action_34) , (33,alex_action_34) , (32,alex_action_34) , (31,alex_action_34) , (30,alex_action_34) , (29,alex_action_34) , (28,alex_action_34) , (27,alex_action_34) , (26,alex_action_34) , (25,alex_action_34) , (24,alex_action_34) , (23,alex_action_34) , (22,alex_action_34) , (21,alex_action_34) , (20,alex_action_34) , (19,alex_action_34) , (18,alex_action_34) , (17,alex_action_34) , (16,alex_action_34) , (15,alex_action_34) , (14,alex_action_34) , (13,alex_action_34) , (12,alex_action_34) , (11,alex_action_34) , (10,alex_action_34) , (9,alex_action_34) , (8,alex_action_34) , (7,alex_action_34) , (6,alex_action_35) , (5,alex_action_36) , (4,alex_action_36) , (3,alex_action_37) , (2,alex_action_38) , (1,alex_action_38) , (0,alex_action_39) ] {-# LINE 129 "examples/ghc/ghc/compiler/cmm/CmmLex.x" #-} data CmmToken = CmmT_SpecChar Char | CmmT_DotDot | CmmT_DoubleColon | CmmT_Shr | CmmT_Shl | CmmT_Ge | CmmT_Le | CmmT_Eq | CmmT_Ne | CmmT_BoolAnd | CmmT_BoolOr | CmmT_CLOSURE | CmmT_INFO_TABLE | CmmT_INFO_TABLE_RET | CmmT_INFO_TABLE_FUN | CmmT_INFO_TABLE_CONSTR | CmmT_INFO_TABLE_SELECTOR | CmmT_else | CmmT_export | CmmT_section | CmmT_goto | CmmT_if | CmmT_call | CmmT_jump | CmmT_foreign | CmmT_never | CmmT_prim | CmmT_reserve | CmmT_return | CmmT_returns | CmmT_import | CmmT_switch | CmmT_case | CmmT_default | CmmT_push | CmmT_unwind | CmmT_bits8 | CmmT_bits16 | CmmT_bits32 | CmmT_bits64 | CmmT_bits128 | CmmT_bits256 | CmmT_bits512 | CmmT_float32 | CmmT_float64 | CmmT_gcptr | CmmT_GlobalReg GlobalReg | CmmT_Name FastString | CmmT_String String | CmmT_Int Integer | CmmT_Float Rational | CmmT_EOF deriving (Show) -- ----------------------------------------------------------------------------- -- Lexer actions type Action = RealSrcSpan -> StringBuffer -> Int -> PD (RealLocated CmmToken) begin :: Int -> Action begin code _span _str _len = do liftP (pushLexState code); lexToken pop :: Action pop _span _buf _len = liftP popLexState >> lexToken special_char :: Action special_char span buf _len = return (L span (CmmT_SpecChar (currentChar buf))) kw :: CmmToken -> Action kw tok span _buf _len = return (L span tok) global_regN :: (Int -> GlobalReg) -> Action global_regN con span buf len = return (L span (CmmT_GlobalReg (con (fromIntegral n)))) where buf' = stepOn buf n = parseUnsignedInteger buf' (len-1) 10 octDecDigit global_reg :: GlobalReg -> Action global_reg r span _buf _len = return (L span (CmmT_GlobalReg r)) strtoken :: (String -> CmmToken) -> Action strtoken f span buf len = return (L span $! (f $! lexemeToString buf len)) name :: Action name span buf len = case lookupUFM reservedWordsFM fs of Just tok -> return (L span tok) Nothing -> return (L span (CmmT_Name fs)) where fs = lexemeToFastString buf len reservedWordsFM = listToUFM $ map (\(x, y) -> (mkFastString x, y)) [ ( "CLOSURE", CmmT_CLOSURE ), ( "INFO_TABLE", CmmT_INFO_TABLE ), ( "INFO_TABLE_RET", CmmT_INFO_TABLE_RET ), ( "INFO_TABLE_FUN", CmmT_INFO_TABLE_FUN ), ( "INFO_TABLE_CONSTR", CmmT_INFO_TABLE_CONSTR ), ( "INFO_TABLE_SELECTOR",CmmT_INFO_TABLE_SELECTOR ), ( "else", CmmT_else ), ( "export", CmmT_export ), ( "section", CmmT_section ), ( "goto", CmmT_goto ), ( "if", CmmT_if ), ( "call", CmmT_call ), ( "jump", CmmT_jump ), ( "foreign", CmmT_foreign ), ( "never", CmmT_never ), ( "prim", CmmT_prim ), ( "reserve", CmmT_reserve ), ( "return", CmmT_return ), ( "returns", CmmT_returns ), ( "import", CmmT_import ), ( "switch", CmmT_switch ), ( "case", CmmT_case ), ( "default", CmmT_default ), ( "push", CmmT_push ), ( "unwind", CmmT_unwind ), ( "bits8", CmmT_bits8 ), ( "bits16", CmmT_bits16 ), ( "bits32", CmmT_bits32 ), ( "bits64", CmmT_bits64 ), ( "bits128", CmmT_bits128 ), ( "bits256", CmmT_bits256 ), ( "bits512", CmmT_bits512 ), ( "float32", CmmT_float32 ), ( "float64", CmmT_float64 ), -- New forms ( "b8", CmmT_bits8 ), ( "b16", CmmT_bits16 ), ( "b32", CmmT_bits32 ), ( "b64", CmmT_bits64 ), ( "b128", CmmT_bits128 ), ( "b256", CmmT_bits256 ), ( "b512", CmmT_bits512 ), ( "f32", CmmT_float32 ), ( "f64", CmmT_float64 ), ( "gcptr", CmmT_gcptr ) ] tok_decimal span buf len = return (L span (CmmT_Int $! parseUnsignedInteger buf len 10 octDecDigit)) tok_octal span buf len = return (L span (CmmT_Int $! parseUnsignedInteger (offsetBytes 1 buf) (len-1) 8 octDecDigit)) tok_hexadecimal span buf len = return (L span (CmmT_Int $! parseUnsignedInteger (offsetBytes 2 buf) (len-2) 16 hexDigit)) tok_float str = CmmT_Float $! readRational str tok_string str = CmmT_String (read str) -- urk, not quite right, but it'll do for now -- ----------------------------------------------------------------------------- -- Line pragmas setLine :: Int -> Action setLine code span buf len = do let line = parseUnsignedInteger buf len 10 octDecDigit liftP $ do setSrcLoc (mkRealSrcLoc (srcSpanFile span) (fromIntegral line - 1) 1) -- subtract one: the line number refers to the *following* line -- trace ("setLine " ++ show line) $ do popLexState >> pushLexState code lexToken setFile :: Int -> Action setFile code span buf len = do let file = lexemeToFastString (stepOn buf) (len-2) liftP $ do setSrcLoc (mkRealSrcLoc file (srcSpanEndLine span) (srcSpanEndCol span)) popLexState >> pushLexState code lexToken -- ----------------------------------------------------------------------------- -- This is the top-level function: called from the parser each time a -- new token is to be read from the input. cmmlex :: (Located CmmToken -> PD a) -> PD a cmmlex cont = do (L span tok) <- lexToken --trace ("token: " ++ show tok) $ do cont (L (RealSrcSpan span) tok) lexToken :: PD (RealLocated CmmToken) lexToken = do inp@(loc1,buf) <- getInput sc <- liftP getLexState case alexScan inp sc of AlexEOF -> do let span = mkRealSrcSpan loc1 loc1 liftP (setLastToken span 0) return (L span CmmT_EOF) AlexError (loc2,_) -> liftP $ failLocMsgP loc1 loc2 "lexical error" AlexSkip inp2 _ -> do setInput inp2 lexToken AlexToken inp2@(end,_buf2) len t -> do setInput inp2 let span = mkRealSrcSpan loc1 end span `seq` liftP (setLastToken span len) t span buf len -- ----------------------------------------------------------------------------- -- Monad stuff -- Stuff that Alex needs to know about our input type: type AlexInput = (RealSrcLoc,StringBuffer) alexInputPrevChar :: AlexInput -> Char alexInputPrevChar (_,s) = prevChar s '\n' -- backwards compatibility for Alex 2.x alexGetChar :: AlexInput -> Maybe (Char,AlexInput) alexGetChar inp = case alexGetByte inp of Nothing -> Nothing Just (b,i) -> c `seq` Just (c,i) where c = chr $ fromIntegral b alexGetByte :: AlexInput -> Maybe (Word8,AlexInput) alexGetByte (loc,s) | atEnd s = Nothing | otherwise = b `seq` loc' `seq` s' `seq` Just (b, (loc', s')) where c = currentChar s b = fromIntegral $ ord $ c loc' = advanceSrcLoc loc c s' = stepOn s getInput :: PD AlexInput getInput = PD $ \_ s@PState{ loc=l, buffer=b } -> POk s (l,b) setInput :: AlexInput -> PD () setInput (l,b) = PD $ \_ s -> POk s{ loc=l, buffer=b } () line_prag,line_prag1,line_prag2 :: Int line_prag = 1 line_prag1 = 2 line_prag2 = 3 alex_action_2 = begin line_prag alex_action_3 = setLine line_prag1 alex_action_4 = setFile line_prag2 alex_action_5 = pop alex_action_7 = special_char alex_action_8 = kw CmmT_DotDot alex_action_9 = kw CmmT_DoubleColon alex_action_10 = kw CmmT_Shr alex_action_11 = kw CmmT_Shl alex_action_12 = kw CmmT_Ge alex_action_13 = kw CmmT_Le alex_action_14 = kw CmmT_Eq alex_action_15 = kw CmmT_Ne alex_action_16 = kw CmmT_BoolAnd alex_action_17 = kw CmmT_BoolOr alex_action_18 = global_regN (\n -> VanillaReg n VGcPtr) alex_action_19 = global_regN (\n -> VanillaReg n VNonGcPtr) alex_action_20 = global_regN FloatReg alex_action_21 = global_regN DoubleReg alex_action_22 = global_regN LongReg alex_action_23 = global_reg Sp alex_action_24 = global_reg SpLim alex_action_25 = global_reg Hp alex_action_26 = global_reg HpLim alex_action_27 = global_reg CCCS alex_action_28 = global_reg CurrentTSO alex_action_29 = global_reg CurrentNursery alex_action_30 = global_reg HpAlloc alex_action_31 = global_reg BaseReg alex_action_32 = global_reg MachSp alex_action_33 = global_reg UnwindReturnReg alex_action_34 = name alex_action_35 = tok_octal alex_action_36 = tok_decimal alex_action_37 = tok_hexadecimal alex_action_38 = strtoken tok_float alex_action_39 = strtoken tok_string {-# LINE 1 "templates/GenericTemplate.hs" #-} -- ----------------------------------------------------------------------------- -- ALEX TEMPLATE -- -- This code is in the PUBLIC DOMAIN; you may copy it freely and use -- it for any purpose whatsoever. -- ----------------------------------------------------------------------------- -- INTERNALS and main scanner engine alexIndexInt16OffAddr arr off = arr ! off alexIndexInt32OffAddr arr off = arr ! off quickIndex arr i = arr ! i -- ----------------------------------------------------------------------------- -- Main lexing routines data AlexReturn a = AlexEOF | AlexError !AlexInput | AlexSkip !AlexInput !Int | AlexToken !AlexInput !Int a -- alexScan :: AlexInput -> StartCode -> AlexReturn a alexScan input__ (sc) = alexScanUser undefined input__ (sc) alexScanUser user__ input__ (sc) = case alex_scan_tkn user__ input__ (0) input__ sc AlexNone of (AlexNone, input__') -> case alexGetByte input__ of Nothing -> AlexEOF Just _ -> AlexError input__' (AlexLastSkip input__'' len, _) -> AlexSkip input__'' len (AlexLastAcc k input__''' len, _) -> AlexToken input__''' len (alex_actions ! k) -- Push the input through the DFA, remembering the most recent accepting -- state it encountered. alex_scan_tkn user__ orig_input len input__ s last_acc = input__ `seq` -- strict in the input let new_acc = (check_accs (alex_accept `quickIndex` (s))) in new_acc `seq` case alexGetByte input__ of Nothing -> (new_acc, input__) Just (c, new_input) -> case fromIntegral c of { (ord_c) -> let base = alexIndexInt32OffAddr alex_base s offset = (base + ord_c) check = alexIndexInt16OffAddr alex_check offset new_s = if (offset >= (0)) && (check == ord_c) then alexIndexInt16OffAddr alex_table offset else alexIndexInt16OffAddr alex_deflt s in case new_s of (-1) -> (new_acc, input__) -- on an error, we want to keep the input *before* the -- character that failed, not after. _ -> alex_scan_tkn user__ orig_input (if c < 0x80 || c >= 0xC0 then (len + (1)) else len) -- note that the length is increased ONLY if this is the 1st byte in a char encoding) new_input new_s new_acc } where check_accs (AlexAccNone) = last_acc check_accs (AlexAcc a ) = AlexLastAcc a input__ (len) check_accs (AlexAccSkip) = AlexLastSkip input__ (len) check_accs (AlexAccPred a predx rest) | predx user__ orig_input (len) input__ = AlexLastAcc a input__ (len) | otherwise = check_accs rest check_accs (AlexAccSkipPred predx rest) | predx user__ orig_input (len) input__ = AlexLastSkip input__ (len) | otherwise = check_accs rest data AlexLastAcc = AlexNone | AlexLastAcc !Int !AlexInput !Int | AlexLastSkip !AlexInput !Int data AlexAcc user = AlexAccNone | AlexAcc Int | AlexAccSkip | AlexAccPred Int (AlexAccPred user) (AlexAcc user) | AlexAccSkipPred (AlexAccPred user) (AlexAcc user) type AlexAccPred user = user -> AlexInput -> Int -> AlexInput -> Bool -- ----------------------------------------------------------------------------- -- Predicates on a rule alexAndPred p1 p2 user__ in1 len in2 = p1 user__ in1 len in2 && p2 user__ in1 len in2 --alexPrevCharIsPred :: Char -> AlexAccPred _ alexPrevCharIs c _ input__ _ _ = c == alexInputPrevChar input__ alexPrevCharMatches f _ input__ _ _ = f (alexInputPrevChar input__) --alexPrevCharIsOneOfPred :: Array Char Bool -> AlexAccPred _ alexPrevCharIsOneOf arr _ input__ _ _ = arr ! alexInputPrevChar input__ --alexRightContext :: Int -> AlexAccPred _ alexRightContext (sc) user__ _ _ input__ = case alex_scan_tkn user__ input__ (0) input__ sc AlexNone of (AlexNone, _) -> False _ -> True -- TODO: there's no need to find the longest -- match when checking the right context, just -- the first match will do.
antalsz/hs-to-coq
examples/ghc/gen-files/CmmLex.hs
mit
284,339
0
25
152,799
136,484
87,044
49,440
37,273
9
module GitHub.Users.Emails where import GitHub.Internal emails = currentUser <> "/emails" --| GET /user/emails getCurrentUserEmails :: GitHub UserEmailsData getCurrentUserEmails = ghGet [] emails --| POST /user/emails addEmailAddresses :: [Text] -> GitHub UserEmailsData addEmailAddresses = ghPost emails --| DELETE /user/emails deleteEmailAddresses :: [Text] -> GitHub () deleteEmailAddresses = ghDelete' emails
SaneApp/github-api
src/GitHub/Users/Emails.hs
mit
422
10
8
57
150
77
73
-1
-1
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ExtendedDefaultRules #-} {-# OPTIONS_GHC -fno-warn-type-defaults #-} import Test.Framework (defaultMain, testGroup, Test) import Test.Framework.Providers.HUnit import Test.HUnit hiding (Test, assert) import System.FilePath (searchPathSeparator) import System.Info (os) import Prelude hiding (FilePath) import Control.Monad.IO.Class import Shelly import Data.List (sort) import Data.Text (Text) import Data.Monoid import qualified Data.Text as T import Paths_c2hs default (T.Text) main :: IO () main = defaultMain tests c2hsShelly :: MonadIO m => Sh a -> m a c2hsShelly as = shelly $ do oldpath <- get_env_text "PATH" let newpath = "../../../dist/build/c2hs:" <> oldpath setenv "PATH" newpath as cc :: FilePath cc = if os == "cygwin32" || os == "mingw32" then "gcc" else "cc" tests :: [Test] tests = [ testGroup "Bugs" $ [ testCase "call_capital (issue #??)" call_capital , testCase "Issue #7" issue07 , testCase "Issue #9" issue09 , testCase "Issue #10" issue10 , testCase "Issue #15" issue15 , testCase "Issue #16" issue16 , testCase "Issue #19" issue19 , testCase "Issue #20" issue20 , testCase "Issue #22" issue22 , testCase "Issue #23" issue23 , testCase "Issue #25" issue25 , testCase "Issue #29" issue29 , testCase "Issue #30" issue30 , testCase "Issue #31" issue31 , testCase "Issue #32" issue32 , testCase "Issue #36" issue36 , testCase "Issue #38" issue38 , testCase "Issue #43" issue43 , testCase "Issue #44" issue44 , testCase "Issue #45" issue45 , testCase "Issue #46" issue46 , testCase "Issue #47" issue47 , testCase "Issue #51" issue51 , testCase "Issue #54" issue54 , testCase "Issue #60" issue60 , testCase "Issue #62" issue62 , testCase "Issue #65" issue65 , testCase "Issue #69" issue69 , testCase "Issue #70" issue70 , testCase "Issue #73" issue73 , testCase "Issue #75" issue75 , testCase "Issue #79" issue79 , testCase "Issue #80" issue80 , testCase "Issue #82" issue82 , testCase "Issue #93" issue93 , testCase "Issue #95" issue95 , testCase "Issue #96" issue96 , testCase "Issue #97" issue97 , testCase "Issue #98" issue98 , testCase "Issue #103" issue103 , testCase "Issue #107" issue107 , testCase "Issue #113" issue113 , testCase "Issue #115" issue115 , testCase "Issue #116" issue116 , testCase "Issue #117" issue117 , testCase "Issue #123" issue123 , testCase "Issue #127" issue127 , testCase "Issue #128" issue128 , testCase "Issue #130" issue130 , testCase "Issue #131" issue131 , testCase "Issue #133" issue133 , testCase "Issue #134" issue134 , testCase "Issue #136" issue136 ] ++ -- Some tests that won't work on Windows. if os /= "cygwin32" && os /= "mingw32" then [ testCase "Issue #48" issue48 , testCase "Issue #83" issue83 , testCase "Issue #102" issue102 ] else [ ] ] call_capital :: Assertion call_capital = c2hsShelly $ chdir "tests/bugs/call_capital" $ do mapM_ rm_f ["Capital.hs", "Capital.chs.h", "Capital.chi", "Capital_c.o", "Capital"] cmd "c2hs" "-d" "genbind" "Capital.chs" cmd cc "-c" "-o" "Capital_c.o" "Capital.c" cmd "ghc" "--make" "-cpp" "Capital_c.o" "Capital.hs" res <- absPath "./Capital" >>= cmd let expected = ["upper C();", "lower c();", "upper C();"] liftIO $ assertBool "" (T.lines res == expected) issue136 :: Assertion issue136 = build_issue_tolerant 136 issue134 :: Assertion issue134 = hs_only_build_issue 134 issue133 :: Assertion issue133 = hs_only_build_issue 133 issue131 :: Assertion issue131 = c2hsShelly $ chdir "tests/bugs/issue-131" $ do mapM_ rm_f ["Issue131.hs", "Issue131.chs.h", "Issue131.chs.c", "Issue131.chi", "issue131_c.o", "Issue131.chs.o", "Issue131"] cmd "c2hs" "Issue131.chs" cmd cc "-c" "-o" "issue131_c.o" "issue131.c" cmd cc "-c" "Issue131.chs.c" cmd "ghc" "--make" "issue131_c.o" "Issue131.chs.o" "Issue131.hs" res <- absPath "./Issue131" >>= cmd let expected = ["5", "3", "True", "False"] liftIO $ assertBool "" (T.lines res == expected) issue130 :: Assertion issue130 = expect_issue 130 ["3", "3"] issue128 :: Assertion issue128 = c2hsShelly $ chdir "tests/bugs/issue-128" $ do mapM_ rm_f ["Issue128.hs", "Issue128.chs.h", "Issue128.chs.c", "Issue128.chi", "issue128_c.o", "Issue128.chs.o", "Issue128"] cmd "c2hs" "Issue128.chs" cmd cc "-c" "-o" "issue128_c.o" "issue128.c" cmd cc "-c" "Issue128.chs.c" cmd "ghc" "--make" "issue128_c.o" "Issue128.chs.o" "Issue128.hs" res <- absPath "./Issue128" >>= cmd let expected = ["5", "3", "True", "False", "10", "False", "12", "True", "7", "False", "8", "True"] liftIO $ assertBool "" (T.lines res == expected) issue127 :: Assertion issue127 = expect_issue 127 ["True", "False"] issue125 :: Assertion issue125 = expect_issue 125 ["NYI"] issue123 :: Assertion issue123 = expect_issue 123 ["[8,43,94]", "[7,42,93]", "[2,4,8]", "[3,9,27]"] issue117 :: Assertion issue117 = c2hsShelly $ chdir "tests/bugs/issue-117" $ do mapM_ rm_f ["Issue117.hs", "Issue117.chs.h", "Issue117.chs.c", "Issue117.chi", "issue117_c.o", "Issue117.chs.o", "Issue117"] cmd "c2hs" "Issue117.chs" cmd cc "-c" "-o" "issue117_c.o" "issue117.c" cmd cc "-c" "Issue117.chs.c" cmd "ghc" "--make" "issue117_c.o" "Issue117.chs.o" "Issue117.hs" res <- absPath "./Issue117" >>= cmd let expected = ["5"] liftIO $ assertBool "" (T.lines res == expected) issue116 :: Assertion issue116 = build_issue 116 issue115 :: Assertion issue115 = expect_issue 115 ["[8,43,94]", "[7,42,93]"] issue113 :: Assertion issue113 = build_issue 113 issue107 :: Assertion issue107 = hs_only_expect_issue 107 True ["True"] issue103 :: Assertion issue103 = c2hsShelly $ chdir "tests/bugs/issue-103" $ do mapM_ rm_f ["Issue103.hs", "Issue103.chs.h", "Issue103.chi", "Issue103A.hs", "Issue103A.chs.h", "Issue103A.chi", "issue103_c.o", "Issue103"] cmd "c2hs" "Issue103A.chs" cmd "c2hs" "Issue103.chs" cmd cc "-c" "-o" "issue103_c.o" "issue103.c" cmd "ghc" "--make" "issue103_c.o" "Issue103A.hs" "Issue103.hs" res <- absPath "./Issue103" >>= cmd let expected = ["1", "2", "3"] liftIO $ assertBool "" (T.lines res == expected) issue102 :: Assertion issue102 = hs_only_expect_issue 102 False ["TST 1: 1234", "TST 2: 13 47", "TST 3: testing", "Unlocked"] issue98 :: Assertion issue98 = build_issue 98 issue97 :: Assertion issue97 = c2hsShelly $ chdir "tests/bugs/issue-97" $ do mapM_ rm_f ["Issue97.hs", "Issue97.chs.h", "Issue97.chi", "Issue97A.hs", "Issue97A.chs.h", "Issue97A.chi", "issue97_c.o", "Issue97"] cmd "c2hs" "Issue97A.chs" cmd "c2hs" "Issue97.chs" cmd cc "-c" "-o" "issue97_c.o" "issue97.c" cmd "ghc" "--make" "issue97_c.o" "Issue97A.hs" "Issue97.hs" res <- absPath "./Issue97" >>= cmd let expected = ["42"] liftIO $ assertBool "" (T.lines res == expected) issue96 :: Assertion issue96 = build_issue 96 issue95 :: Assertion issue95 = build_issue 95 issue93 :: Assertion issue93 = build_issue_tolerant 93 issue82 :: Assertion issue82 = hs_only_build_issue 82 issue83 :: Assertion issue83 = hs_only_expect_issue 83 True ["(True,True)", "TEST_VAL", "8415", "8415", "TESTING"] issue80 :: Assertion issue80 = build_issue 80 issue79 :: Assertion issue79 = expect_issue 79 ["A=1", "B=2", "C=2", "D=3"] issue75 :: Assertion issue75 = build_issue 75 issue73 :: Assertion issue73 = unordered_expect_issue 73 [ "Allocated struct3" , "Foreign pointer: 3" , "Allocated struct3" , "Foreign pointer: 3" , "Allocated struct4" , "Foreign newtype pointer: 4" , "Allocated struct4" , "Foreign newtype pointer: 4" , "Freeing struct3" , "Freeing struct4" ] issue70 :: Assertion issue70 = build_issue 70 issue69 :: Assertion issue69 = build_issue 69 issue65 :: Assertion issue65 = expect_issue 65 ["123", "3.14", "\"hello\""] issue62 :: Assertion issue62 = build_issue 62 issue60 :: Assertion issue60 = build_issue 60 issue54 :: Assertion issue54 = expect_issue 54 ["2", "0.2", "2", "0.2", "3", "0.3", "3", "0.3", "3", "0.3", "3", "0.3"] issue51 :: Assertion issue51 = do expect_issue_with True True 51 "nonGNU" [] ["0"] expect_issue_with True True 51 "GNU" [] ["1"] issue48 :: Assertion issue48 = expect_issue 48 ["2", "5"] issue47 :: Assertion issue47 = build_issue 47 issue46 :: Assertion issue46 = expect_issue 46 ["(1,2.5)"] issue45 :: Assertion issue45 = build_issue 45 issue44 :: Assertion issue44 = build_issue 44 issue43 :: Assertion issue43 = expect_issue 43 ["Test1A=0", "Test1B=1", "Test1C=5", "Test1D=6", "AnonA=8", "AnonB=9", "AnonC=15", "AnonD=16"] issue38 :: Assertion issue38 = expect_issue 38 ["Enum OK"] issue36 :: Assertion issue36 = hs_only_build_issue 36 issue32 :: Assertion issue32 = expect_issue 32 ["1234", "1", "523"] issue31 :: Assertion issue31 = expect_issue 31 ["Enum OK", "Pointer 1: 1 1", "Pointer 2: 2", "Foreign pointer: 3", "Foreign newtype pointer: 4"] -- This is tricky to test since it's Windows-specific, but we can at -- least make sure that paths with spaces work OK. issue30 :: Assertion issue30 = c2hsShelly $ chdir "tests/bugs/issue-30" $ do mkdir_p "test 1" mkdir_p "test 2" mapM_ rm_f ["Issue30.hs", "Issue30.chs.h", "Issue30.chi", "Issue30Aux1.hs", "Issue30Aux1.chs.h", "test 1/Issue30Aux1.chi", "Issue30Aux2.hs", "Issue30Aux2.chs.h", "test 2/Issue30Aux2.chi", "issue30_c.o", "issue30aux1_c.o", "issue30aux2_c.o", "Issue30"] cmd "c2hs" "Issue30Aux1.chs" mv "Issue30Aux1.chi" "test 1" cmd "c2hs" "Issue30Aux2.chs" mv "Issue30Aux2.chi" "test 2" let sp = T.pack $ "test 1" ++ [searchPathSeparator] ++ "test 2" cmd "c2hs" "--include" sp "Issue30.chs" cmd cc "-c" "-o" "issue30_c.o" "issue30.c" cmd cc "-c" "-o" "issue30aux1_c.o" "issue30aux1.c" cmd cc "-c" "-o" "issue30aux2_c.o" "issue30aux2.c" cmd "ghc" "--make" "issue30_c.o" "issue30aux1_c.o" "issue30aux2_c.o" "Issue30Aux1.hs" "Issue30Aux2.hs" "Issue30.hs" res <- absPath "./Issue30" >>= cmd let expected = ["3", "2", "4"] liftIO $ assertBool "" (T.lines res == expected) issue29 :: Assertion issue29 = c2hsShelly $ do errExit False $ do cd "tests/bugs/issue-29" mapM_ rm_f ["Issue29.hs", "Issue29.chs.h", "Issue29.chi"] run "c2hs" [toTextIgnore "Issue29.chs"] code <- lastExitCode liftIO $ assertBool "" (code == 0) issue25 :: Assertion issue25 = hs_only_expect_issue 25 True ["-1", "abcdef"] issue23 :: Assertion issue23 = expect_issue 23 ["H1"] issue22 :: Assertion issue22 = expect_issue 22 ["abcdef", "2", "20"] issue20 :: Assertion issue20 = expect_issue 20 ["4"] issue19 :: Assertion issue19 = expect_issue 19 ["Did it!"] issue16 :: Assertion issue16 = build_issue 16 issue15 :: Assertion issue15 = expect_issue 15 ["True"] issue10 :: Assertion issue10 = expect_issue 10 ["SAME", "SAME", "SAME", "SAME"] issue09 :: Assertion issue09 = expect_issue 9 $ archdep ++ ["(32,64)", "64", "OK"] where archdep | (maxBound::Int) == 2147483647 = ["PTA:4", "AOP:16"] -- 32 bit | otherwise = ["PTA:8", "AOP:32"] -- 64 bit issue07 :: Assertion issue07 = c2hsShelly $ do errExit False $ do cd "tests/bugs/issue-7" mapM_ rm_f ["Issue7.hs", "Issue7.chs.h", "Issue7.chi"] setenv "LANG" "zh_CN.utf8" run "c2hs" [toTextIgnore "Issue7.chs"] code <- lastExitCode liftIO $ assertBool "" (code == 0) do_issue_build :: Bool -> Bool -> Int -> String -> [Text] -> Sh () do_issue_build strict cbuild n ext c2hsargs = let wdir = "tests/bugs" </> ("issue-" <> show n) lc = "issue" <> show n lcc = lc <> "_c" uc = fromText $ T.pack $ "Issue" <> show n <> (if ext == "" then "" else "_" <> ext) in do cd wdir mapM_ rm_f [uc <.> "hs", uc <.> "chs.h", uc <.> "chi", lcc <.> "o", uc] run "c2hs" $ c2hsargs ++ [toTextIgnore $ uc <.> "chs"] when cbuild $ cmd cc "-c" "-o" (lcc <.> "o") (lc <.> "c") case (strict, cbuild) of (True, True) -> cmd "ghc" "-Wall" "-Werror" "--make" (lcc <.> "o") (uc <.> "hs") (False, True) -> cmd "ghc" "--make" (lcc <.> "o") (uc <.> "hs") (True, False) -> cmd "ghc" "-Wall" "-Werror" "--make" (uc <.> "hs") (False, False) -> cmd "ghc" "--make" (uc <.> "hs") expect_issue :: Int -> [Text] -> Assertion expect_issue n expected = expect_issue_with True True n "" [] expected unordered_expect_issue :: Int -> [Text] -> Assertion unordered_expect_issue n expected = expect_issue_with False True n "" [] expected hs_only_expect_issue :: Int -> Bool -> [Text] -> Assertion hs_only_expect_issue n ordered expected = expect_issue_with ordered False n "" [] expected expect_issue_with :: Bool -> Bool -> Int -> String -> [Text] -> [Text] -> Assertion expect_issue_with ordered cbuild n ext c2hsargs expected = c2hsShelly $ do do_issue_build True cbuild n ext c2hsargs res <- absPath ("." </> (fromText $ T.pack $ "Issue" <> show n <> (if ext == "" then "" else "_" <> ext))) >>= cmd liftIO $ assertBool "" $ case ordered of True -> T.lines res == expected False -> sort (T.lines res) == sort expected build_issue_with :: Bool -> Bool -> Int -> [Text] -> Assertion build_issue_with strict cbuild n c2hsargs = c2hsShelly $ do errExit False $ do_issue_build strict cbuild n "" c2hsargs code <- lastExitCode liftIO $ assertBool "" (code == 0) build_issue :: Int -> Assertion build_issue n = build_issue_with True True n [] build_issue_tolerant :: Int -> Assertion build_issue_tolerant n = build_issue_with False True n [] hs_only_build_issue :: Int -> Assertion hs_only_build_issue n = build_issue_with True False n []
ian-ross/c2hs-macos-test
c2hs-0.26.1/tests/test-bugs.hs
mit
14,696
0
18
3,553
4,025
2,088
1,937
371
5
module Main where import System.IO import Parser import AvailableExpression import VeryBusy import ReachingDefinition import LiveVariables import ConstantPropagation import MonotoneFramework import qualified Data.Set as Set import qualified Data.Map as Map main :: IO () main = do withFile "test/while2.js" ReadMode (\handle -> do source <- hGetContents handle case parse source of Right p@(s,_, _) -> do putStr "\nAvailable Expression\n" let (MFP c d) = availableExpression p c' = Map.toList c putStr "Entry\n" pMFP c' let d' = Map.toList d putStr "Exit\n" pMFP d' putStr "\nVery Busy Expression\n" let (MFP cv dv) = veryBusyExpression p cv' = Map.toList cv dv' = Map.toList dv putStr "Entry\n" pMFP cv' putStr "Exits\n" pMFP dv' putStrLn "\nReaching Definition" let (MFP cr dr) = reachingDefinition p cr' = Map.toList cr dr' = Map.toList dr putStrLn "Extry" pMFP cr' putStrLn "Exit" pMFP dr' putStrLn "\nLive Variables" let (MFP cl dl) = liveVariables p cl' = Map.toList cl dl' = Map.toList dl putStrLn "Entry" pMFP cl' putStrLn "Exit" pMFP dl' putStrLn "\nLive Variables" let (MFP cc dc) = constants p cc' = Map.toList cc dc' = Map.toList dc putStrLn "Entry" print cc' putStrLn "Exit" print dc' Left error -> putStr error) pMFP :: Show a => [(Integer, Set.Set a)] -> IO () pMFP = mapM_ (\(l, s) -> putStr $ show l ++ " : " ++ show (Set.toList s) ++ "\n")
fiigii/dataflow
Main.hs
mit
2,823
0
21
1,688
578
265
313
59
2
-- Intermission: Exercises -- Given a function and its type, tell us what type results from applying some -- or all of the arguments. -- 1. If the type of f is a -> a -> a -> a, and the type of x is Char then the -- type of f x is -- a) Char -> Char -> Char *** -- b) x -> x -> x -> x -- c) a -> a -> a -- d) a -> a -> a -> Char -- 2. If the type of g is a -> b -> c -> b, then the type of g 0 'c' "woot" is -- a) String -- b) Char -> String -- c) Int -- d) Char *** -- 3. If the type of h is (Num a, Num b) => a -> b -> b, then the type of h 1.0 2is -- a) Double -- b) Integer -- c) Integral b => b -- d) Num b => b *** -- 4. If the type of h is (Num a, Num b) => a -> b -> b,then the type of h 1 -- (5.5 :: Double) is -- a) Integer -- b) Fractional b => b -- c) Double *** -- d) Num b => b -- 5. If the type of jackal is (Ord a, Eq b) => a -> b -> a, then the type of -- jackal "keyboard" "has the word jackal in it" -- a) [Char] *** -- b) Eq b => b -- c) b -> [Char] -- d) b -- e) Eq b => b -> [Char] -- 6. If the type of jackal is (Ord a, Eq b) => a -> b -> a, then the type of -- jackal "keyboard" -- a) b -- b) Eq b => b -- c) [Char] -- d) b -> [Char] -- e) Eq b => b -> [Char] *** -- 7. If the type of kessel is (Ord a, Num b) => a -> b -> a, then the type of -- kessel 1 2 is -- a) Integer -- b) Int -- c) a -- d) (Num a, Ord a) => a -- e) Ord a => a *** -- f) Num a => a -- 8. If the type of kessel is (Ord a, Num b) => a -> b -> a, then the type of -- kessel 1 (2 :: Integer) is -- a) (Num a, Ord a) => a -- b) Int -- c) a -- d) Num a => a -- e) Ord a => a *** -- f) Integer -- 9. If the type of kessel is (Ord a, Num b) => a -> b -> a, then the type of -- kessel (1 :: Integer) 2 is -- a) Num a => a -- b) Ord a => a -- c) Integer *** -- d) (Num a, Ord a) => a -- e) a
diminishedprime/.org
reading-list/haskell_programming_from_first_principles/05_05.hs
mit
1,799
0
2
516
64
63
1
1
0
{-# LANGUAGE Trustworthy #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE StandaloneDeriving #-} module FP15.Evaluator.FP ( module FP15.Evaluator.FP, module Control.Monad.RWS.Strict, module Control.Monad.Except ) where import Control.Applicative import Control.Monad.RWS.Strict import Control.Monad.Except import FP15.Evaluator.FPEnv(FPEnv(..), initial) import FP15.Evaluator.RuntimeError import FP15.Evaluator.FPValue type R = FPEnv FPValue type W = () type S = () initR :: R initR = initial initS :: S initS = () -- | The 'FP' monad is the monad for executing FP15 code. It contains the following behaviors: -- -- 1. Side effects ('IO') -- 2. Read-only context (@RWST FPEnv@) -- 3. Error handling (@ErrorT RuntimeError@) -- -- Since 'ErrorT' is the outermost monad transformer in the transformer stack, -- the context is available even if an error has occurred. See the signature of -- 'runFP' for more details. newtype FP a = FP { unFP :: ExceptT RuntimeError (RWST R W S IO) a } deriving instance MonadIO FP deriving instance MonadFix FP deriving instance MonadError RuntimeError FP deriving instance MonadReader R FP deriving instance MonadWriter W FP deriving instance MonadState S FP deriving instance MonadRWS R W S FP instance Monad FP where return = FP . return (FP a) >>= b = FP (a >>= fmap unFP b) instance Applicative FP where pure = return (<*>) = ap instance Functor FP where fmap f (FP x) = FP $ fmap f x runFP :: R -> S -> FP a -> IO (Either RuntimeError a, W, S) runFP r s = flip (`runRWST` r) s . runExceptT . unFP execFP :: FP a -> IO (Either RuntimeError a) execFP fp = (\(a, _, _) -> a) <$> runFP initR initS fp getEnv :: FP R getEnv = ask runIO :: IO a -> FP a runIO = liftIO withEnv :: (R -> R) -> FP a -> FP a withEnv = local getClosure :: FP (R, S) getClosure = (,) <$> getEnv <*> get
Ming-Tang/FP15
src/FP15/Evaluator/FP.hs
mit
1,923
0
10
351
564
318
246
48
1
{-# htermination span :: (a -> Bool) -> [a] -> ([a],[a]) #-}
ComputationWithBoundedResources/ara-inference
doc/tpdb_trs/Haskell/full_haskell/Prelude_span_1.hs
mit
61
0
2
12
3
2
1
1
0
import Prelude hiding ((&&)) halve_a xs = (take n xs, drop n xs) where n = length xs `div` 2 remove n xs = take n xs ++ drop (n + 1) xs funct x xs = take (x + 1) xs ++ drop x xs a && b = if b then a else False
ricca509/haskellFP101x
src/lesson4.hs
mit
262
0
8
108
133
69
64
9
2
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} module Data.Neural.HMatrix.Recurrent.Dropout ( trainSeriesDO , trainSeriesDOMWC , compensateDO ) where import Control.Applicative import Control.Lens import Control.Monad.Primitive import Control.Monad.Random hiding (uniform) import Data.Bool import Data.Neural.HMatrix.Recurrent import Data.Neural.HMatrix.Recurrent.Train import Data.Neural.HMatrix.FLayer import Data.Neural.Types (KnownNet, NeuralActs(..)) import GHC.TypeLits import GHC.TypeLits.List import Numeric.AD.Rank1.Forward import Numeric.LinearAlgebra.Static import System.Random.MWC -- should store `diag m` instead of `m`? data NetMask :: Nat -> [Nat] -> Nat -> * where MaskOL :: NetMask i '[] o MaskIL :: (KnownNat j, KnownNats js) => !(R j) -> !(NetMask j js o) -> NetMask i (j ': js) o infixr 5 `MaskIL` deriving instance Show (NetMask i hs o) trainSeriesDO :: forall i hs o m f. (KnownNet i hs o, MonadRandom m, Foldable f) => NeuralActs (Forward Double) -> Double -- ^ Dropout rate -> Double -- ^ Step size (weights) -> Double -- ^ Step size (state) -> R o -- ^ Target -> f (R i) -- ^ Inputs -> Network i hs o -> m (Network i hs o) trainSeriesDO na doRate step stepS targ inps0 n0 = genNetMask doRate <&> \nm -> let n0M = applyMask nm n0 (ns0M, nu0M) = toNetworkU n0M (dsM, nuShiftsM) = bptt na step targ inps0 ns0M nu0M (ns0, nu0) = toNetworkU n0 in trainStates stepS (nu0 - applyMaskU nm nuShiftsM) ns0 (applyMaskD nm dsM) {-# INLINE trainSeriesDO #-} trainSeriesDOMWC :: forall i hs o m f. (KnownNet i hs o, PrimMonad m, Foldable f) => NeuralActs (Forward Double) -> Double -- ^ Dropout rate -> Double -- ^ Step size (weights) -> Double -- ^ Step size (state) -> R o -- ^ Target -> f (R i) -- ^ Inputs -> Network i hs o -> Gen (PrimState m) -> m (Network i hs o) trainSeriesDOMWC na doRate step stepS targ inps0 n0 g = genNetMaskMWC doRate g <&> \nm -> let n0M = applyMask nm n0 (ns0M, nu0M) = toNetworkU n0M (dsM, nuShiftsM) = bptt na step targ inps0 ns0M nu0M (ns0, nu0) = toNetworkU n0 in trainStates stepS (nu0 - applyMaskU nm nuShiftsM) ns0 (applyMaskD nm dsM) {-# INLINE trainSeriesDOMWC #-} applyMask :: KnownNet i hs o => NetMask i hs o -> Network i hs o -> Network i hs o applyMask = \case MaskOL -> id MaskIL m nm -> \case NetIL (RLayer b wI wS s) nn -> let mM = diag m nnMasked = case applyMask nm nn of NetOL (FLayer b' w') -> NetOL (FLayer b' (w' <> mM)) NetIL (RLayer b' wI' wS' s') nn' -> NetIL (RLayer b' (wI' <> mM) wS' s') nn' in NetIL (RLayer (m * b) (mM <> wI) (mM <> wS <> mM) (m * s)) nnMasked {-# INLINE applyMask #-} applyMaskU :: KnownNet i hs o => NetMask i hs o -> NetworkU i hs o -> NetworkU i hs o applyMaskU = \case MaskOL -> id MaskIL m nm -> \case NetUIL (RLayerU b wI wS) nn -> let mM = diag m nnMasked = case applyMaskU nm nn of NetUOL (FLayer b' w') -> NetUOL (FLayer b' (w' <> mM)) NetUIL (RLayerU b' wI' wS') nn' -> NetUIL (RLayerU b' (wI' <> mM) wS') nn' in NetUIL (RLayerU (m * b) (mM <> wI) (mM <> wS <> mM)) nnMasked {-# INLINE applyMaskU #-} applyMaskD :: forall i hs o. KnownNet i hs o => NetMask i hs o -> Deltas i hs o -> Deltas i hs o applyMaskD = \case MaskOL -> id MaskIL m nm -> \case DeltasIL dI dO (dlt :: Deltas h hs' o) -> let dltMasked :: Deltas h hs' o dltMasked = case applyMaskD nm dlt of DeltasOL dI' -> DeltasOL (m * dI') DeltasIL dI' dO' dlt' -> DeltasIL (m * dI') dO' dlt' in DeltasIL dI (m * dO) dltMasked {-# INLINE applyMaskD #-} genNetMask :: forall i hs o m. (KnownNet i hs o, MonadRandom m) => Double -> m (NetMask i hs o) genNetMask doRate = go natsList where go :: forall j js. NatList js -> m (NetMask j js o) go nl = case nl of ØNL -> return MaskOL _ :<# nl' -> liftA2 MaskIL randomMask (go nl') randomMask :: forall n. KnownNat n => m (R n) randomMask = dvmap (bool 0 1 . (doRate <)) . flip randomVector Uniform <$> getRandom {-# INLINE genNetMask #-} genNetMaskMWC :: forall i hs o m. (KnownNet i hs o, PrimMonad m) => Double -> Gen (PrimState m) -> m (NetMask i hs o) genNetMaskMWC doRate g = go natsList where go :: forall j js. NatList js -> m (NetMask j js o) go nl = case nl of ØNL -> return MaskOL _ :<# nl' -> liftA2 MaskIL randomMask (go nl') randomMask :: forall n. KnownNat n => m (R n) randomMask = dvmap (bool 0 1 . (doRate <)) . flip randomVector Uniform <$> uniform g {-# INLINE genNetMaskMWC #-} compensateDO :: forall i hs o. KnownNet i hs o => Double -> Network i hs o -> Network i hs o compensateDO d = \case NetOL w -> NetOL w NetIL l n -> NetIL l (go n) where go :: forall h hs'. KnownNat h => Network h hs' o -> Network h hs' o go = \case NetOL w -> NetOL (compFLayer w) NetIL w n -> NetIL (compRLayer w) (go n) compFLayer :: forall i' o'. (KnownNat i', KnownNat o') => FLayer i' o' -> FLayer i' o' compFLayer (FLayer b w) = FLayer b (konst d' * w) compRLayer :: forall i' o'. (KnownNat i', KnownNat o') => RLayer i' o' -> RLayer i' o' compRLayer (RLayer b wI wS s) = RLayer b (konst d' * wI) (konst d' * wS) s d' = 1 / (1 - d) {-# INLINE compensateDO #-}
mstksg/neural
src/Data/Neural/HMatrix/Recurrent/Dropout.hs
mit
6,362
0
22
2,161
2,234
1,152
1,082
179
3
{-# LANGUAGE Arrows, TemplateHaskell, BangPatterns #-} {-# OPTIONS -Wall #-} module Game.Input.Input ( userInput -- | TODO: move this somewhere else , untilV ) where --( ---- * Input -- UserInput --, inputNew, inputKeyDown, inputKeyUp --, inputMouseButtonDown, inputMouseButtonUp --, inputUpdateMousePos --, keyDown, keyUp --, keyDownEvent, keyUpEvent ---- * Wires --, InputWire --, stepInput, userInput ---- * Utils --, untilV --) where import Prelude hiding ((.)) import Control.Wire import GHC.Float -- for W.--> import qualified Control.Wire as W import Control.Wire.Unsafe.Event import qualified Data.Set as Set import Control.Monad.State.Strict import Control.Monad.RWS.Strict import qualified Graphics.UI.GLFW as GLFW import Game.Input.Actions import Linear import Game.Render.Core.Camera import Control.Lens data XCButtons = XC'A | XC'B | XC'X | XC'Y | XC'RB | XC'LB | XCHome | XCBack | XCStart | XC'LS | XC'RS deriving (Show, Ord, Eq) buttons :: [XCButtons] buttons = [XC'A, XC'B, XC'X, XC'Y, XC'LB, XC'RB, XCBack, XCStart, XCHome, XC'LS, XC'RS] makeSet :: [GLFW.JoystickButtonState] -> Set.Set XCButtons makeSet ls = foldr (\(s, b) mySet -> if s == GLFW.JoystickButtonState'Pressed then Set.insert b mySet else mySet) Set.empty $ zip ls buttons data XboxController = XboxController { _xcLeftTrigger :: !Double , _xcRightTrigger :: !Double , _xcLeftStick :: !(Double, Double) , _xcRightStick :: !(Double, Double) , _xcPad :: !(Double, Double) , _xcButtons :: !(Set.Set XCButtons) } deriving (Show) newXboxController :: XboxController newXboxController = XboxController { _xcLeftTrigger = 0 , _xcRightTrigger = 0 , _xcLeftStick = (0, 0) , _xcRightStick = (0, 0) , _xcPad = (0, 0) , _xcButtons = Set.empty } makeLenses ''XboxController -- input data data UserInput = UserInput { inputKeys :: !(Set.Set GLFW.Key) , inputMouseButtons :: !(Set.Set GLFW.MouseButton) , inputMousePos :: !(Double, Double) , inputJoystick :: !XboxController , inputPlayerCamera :: !Camera } deriving (Show) data InputMemory = InputMemory { } type InputContext = RWS UserInput InputActions InputMemory type InputSession = Session IO (Timed NominalDiffTime ()) type InputWire a b = Wire (Timed NominalDiffTime ()) () InputContext a b inputNew :: UserInput inputNew = UserInput { inputKeys = Set.empty , inputMouseButtons = Set.empty , inputMousePos = (0, 0) , inputJoystick = newXboxController , inputPlayerCamera = newDefaultCamera 0 0 } inputMemoryNew :: InputMemory inputMemoryNew = InputMemory {} inputUpdateController :: XboxController -> State UserInput () inputUpdateController xc = modify $ \i -> i { inputJoystick = xc } inputSetCamera :: Camera -> State UserInput () inputSetCamera cam = modify $ \i -> i { inputPlayerCamera = cam } inputKeyDown :: GLFW.Key -> State UserInput () inputKeyDown k = modify $ \i -> i { inputKeys = Set.insert k (inputKeys i) } inputKeyUp :: GLFW.Key -> State UserInput () inputKeyUp k = modify $ \i -> i { inputKeys = Set.delete k (inputKeys i) } inputMouseButtonDown :: GLFW.MouseButton -> State UserInput () inputMouseButtonDown mb = modify $ \i -> i { inputMouseButtons = Set.insert mb (inputMouseButtons i) } inputMouseButtonUp :: GLFW.MouseButton -> State UserInput () inputMouseButtonUp mb = modify $ \i -> i { inputMouseButtons = Set.delete mb (inputMouseButtons i) } inputUpdateMousePos :: (Double, Double) -> State UserInput () inputUpdateMousePos pos = modify $ \i -> i { inputMousePos = pos } -- * Basic wires -- | Create a wire that triggers an event as soon as the monad action returns true inputEvent :: InputContext Bool -> InputWire a (Event a) inputEvent cond = mkGenN $ \a -> do eventHappened <- cond return $ if eventHappened then a `seq` (Right (Event a), inputEvent cond) else (Right NoEvent, inputEvent cond) -- | Create a wire that runs as long as the monad action returns true. inputState :: InputContext Bool -> InputWire a a inputState cond = mkGenN $ \a -> do eventHappened <- cond return $ if eventHappened then a `seq` (Right a, inputState cond) else (Left () , inputState cond) inputGet :: InputContext a -> InputWire b a inputGet f = mkGenN $ \a -> do eventHappened <- f return $ eventHappened `seq` (Right eventHappened, inputGet f) keyDownEvent :: GLFW.Key -> InputWire a (Event a) keyDownEvent key = inputEvent (liftM (Set.member key . inputKeys) ask) keyUpEvent :: GLFW.Key -> InputWire a (Event a) keyUpEvent key = inputEvent (liftM (not . Set.member key . inputKeys) ask) keyDown :: GLFW.Key -> InputWire a a keyDown key = inputState (liftM (Set.member key . inputKeys) ask) keyUp :: GLFW.Key -> InputWire a a keyUp key = inputState (liftM (not . Set.member key . inputKeys) ask) buttonDownEvent :: XCButtons -> InputWire a (Event a) buttonDownEvent button = inputEvent (liftM (Set.member button . _xcButtons . inputJoystick) ask) buttonUpEvent :: XCButtons -> InputWire a (Event a) buttonUpEvent button = inputEvent (liftM (not . Set.member button . _xcButtons . inputJoystick) ask) stepInput :: InputWire Int b -> InputSession -> State UserInput () -> IO (InputActions, InputSession, InputWire Int b) stepInput w' session' input = do (dt, session) <- stepSession session' let ((_, !w), _, !actions) = runRWS ( stepWire w' dt (Right 0) ) (execState input inputNew) inputMemoryNew return $ actions `seq` session `seq` w `seq` (actions, session, w) -- * User input directionX :: InputWire a (V2 Float) directionX = pure (V2 1 0) . keyDown GLFW.Key'A . keyUp GLFW.Key'D <|> pure (V2 (-1) 0) . keyDown GLFW.Key'D . keyUp GLFW.Key'A <|> pure 0 directionY :: InputWire a (V2 Float) directionY = pure (V2 0 (-1)) . keyDown GLFW.Key'W . keyUp GLFW.Key'S <|> pure (V2 0 1) . keyDown GLFW.Key'S. keyUp GLFW.Key'W <|> pure 0 --movement = (stopMoveAction . W.when (\(V2 x y) -> x == 0 && y == 0) <|> moveAction) . liftA2 (+) directionX directionY movement :: InputWire a () movement = void (W.when (\(V2 dx dy) -> abs dx < 0.005 && abs dy < 0.005)) . liftA2 (+) directionX directionY W.--> moveAction . liftA2 (+) directionX directionY W.--> stopMoveAction W.--> movement directionController :: InputWire a (V2 Float) directionController = inputGet (liftM (\is -> (\(dx, dy) -> V2 (double2Float dx) (double2Float dy)) $ inputJoystick is ^. xcLeftStick) ask) movementController :: InputWire a () movementController = void (W.when (\(V2 dx dy) -> abs dx < 0.005 && abs dy < 0.005)) . directionController W.--> moveAction . W.when (\(V2 dx dy) -> abs dx > 0.005 || abs dy > 0.005) . directionController W.--> stopMoveAction W.--> movementController untilV :: (Monoid e, Monad m) => W.Wire s e m a (Event b) -> W.Wire s e m a () untilV source = W.until . fmap(\e -> e `seq` ((), e)) source --actionActivate :: InputWire a () --actionActivate = untilV (keyDownEvent GLFW.Key'X) W.--> -- untilV (keyUpEvent GLFW.Key'X ). asSoonAs . keyDownEvent GLFW.Key'X -- W.--> for 0.5 . asSoonAs . activateAction W.--> actionActivate --actionPickup = asSoonAs . keyDownEvent GLFW.Key'C spawn :: InputWire a () spawn = untilV (keyDownEvent GLFW.Key'Space) W.--> for 0.2 . asSoonAs . spawnAction . once . keyDownEvent GLFW.Key'Space W.--> waitOneUpdate -- We need a state update at this point W.--> spawn spawnController :: InputWire a () spawnController = untilV (buttonDownEvent XC'A) W.--> for 0.5 . asSoonAs . spawnAction . once . buttonDownEvent XC'A W.--> waitOneUpdate -- We need a state update at this point W.--> spawnController waitOneUpdate :: InputWire a () waitOneUpdate = mkGenN $ \_ -> return (Right (), inhibit ()) userInput :: InputWire a ((), ()) userInput = proc input -> do _ <- movement -< input _ <- movementController -< input _ <- spawn -< input _ <- spawnController -< input returnA -< ((), ()) stopMoveAction :: InputWire a () stopMoveAction = mkGenN $ \_ -> do writer ((), newInputAction ActionStopMove) return (Right (), inhibit ()) moveAction :: InputWire (V2 Float) () moveAction = mkGenN $ \(V2 x y) -> if abs x < 0.005 && abs y < 0.005 then return (Left (), moveAction) else do writer ((), newInputAction (newMoveAction x y)) return (Right (), moveAction) --activateAction :: InputWire a (Event ()) --activateAction = mkGenN $ \_ -> do -- writer ((), newInputAction (ActionActivate DirNorth)) -- return (Right (Event ()), never) spawnAction :: InputWire a (Event ()) spawnAction = mkGenN $ \_ -> do is <- ask let (mx, my) = inputMousePos is let V2 x y = screenToOpenGLCoords (inputPlayerCamera is) (double2Float mx) (double2Float my) let (lsx, lsy) = inputJoystick is ^. xcLeftStick writer $ if abs lsx > 0.1 || abs lsy > 0.1 then ((), newInputAction (ActionSpawnArrow (-double2Float lsx) (-double2Float lsy))) else ((), newInputAction (ActionSpawnArrow x y)) return (Right (Event ()), never)
mfpi/q-inqu
Game/Input/Input.hs
mit
8,953
217
15
1,664
3,049
1,699
1,350
-1
-1
{-# LANGUAGE DeriveFunctor #-} module Commands where import Control.Monad.Free import Configuration (RobotConfig) data Command = Forward Double -- move forward d centimeters | Backward Double -- move backward d centimeters | Clockwise Double -- turn d radians clockwise | CClockwise Double -- turn d radians counter-clockwise deriving (Eq,Show) data Reading = Barrier Bool -- whether robot hit some barrier or not | Light Double -- light intensity from light sensor | Temperature Double -- value of temperature from temperature sensor | Sound Double -- volume of sound from sound sensor; dB or dB(A) scaling | Custom String String -- reading from custom sensor with given description and serialized value deriving (Eq,Show) data Interaction next = Output Command next | Input String (Reading -> next) deriving (Functor) type Script = Free Interaction forward :: Double -> Script () forward d = liftF $ Output (Forward d) () backward :: Double -> Script () backward d = liftF $ Output (Backward d) () clockwise :: Double -> Script () clockwise d = liftF $ Output (Clockwise d) () cclockwise :: Double -> Script () cclockwise d = liftF $ Output (CClockwise d) () readInput :: String -> Script Reading readInput port = liftF (Input port id) executeCommand :: Command -> Script () executeCommand c = liftF $ Output c () class Monad m => Driver m where initialize :: RobotConfig -> m () output :: Command -> m () input :: String -> m Reading run :: Driver m => Script a -> m a run (Pure a) = return a run (Free (Output cmd next)) = do output cmd run next run (Free (Input v f)) = do i <- input v run $ f i
research-team/robot-dream
src/Commands.hs
mit
1,860
0
9
544
538
276
262
43
1
{-# LANGUAGE ForeignFunctionInterface #-} module Display where import Foreign.C(CInt(..), CFloat(..)) newtype DisplayNumber = DisplayNumber CInt newtype Brightness = Brightness CFloat foreign import ccall getBrightness :: DisplayNumber -> IO Brightness foreign import ccall setBrightness :: DisplayNumber -> Brightness -> IO()
nettsundere/ikiska
src/Display.hs
mit
330
0
9
42
82
49
33
7
0
{-# LANGUAGE OverloadedStrings, GADTs, StandaloneDeriving, DataKinds, FlexibleInstances, KindSignatures #-} module Nginx.Http.Gzip (GzipDirective, gzipDirective) where import Data.Text import Control.Applicative import Data.Attoparsec.Text import Nginx.Types (Context(..), Size, Switch) import Nginx.Utils data GzipDirective (a :: Context) where GzipDirective :: Text -> GzipDirective a GzipCompLevelDirective :: Text -> GzipDirective a GzipMinLengthDirective :: Text -> GzipDirective a GzipDisableDirective :: Text -> GzipDirective a GzipProxiedDirective :: Text -> GzipDirective a GzipVaryDirective :: Switch -> GzipDirective a GzipTypesDirective :: Text -> GzipDirective a deriving instance Show (GzipDirective a) gzipDirective :: Parser (GzipDirective a) gzipDirective = gzipCompLevel <|> gzipMinLength <|> gzipDisable <|> gzipProxied <|> gzipVary <|> gzipTypes <|> gzip gzip = GzipDirective <$> textValueDirective "gzip" gzipCompLevel = GzipCompLevelDirective <$> textValueDirective "gzip_comp_level" gzipMinLength = GzipMinLengthDirective <$> textValueDirective "gzip_min_length" gzipDisable = GzipDisableDirective <$> textValueDirective "gzip_disable" gzipProxied = GzipProxiedDirective <$> textValueDirective "gzip_proxied" gzipVary = GzipVaryDirective <$> switchDirective "gzip_vary" gzipTypes = GzipTypesDirective <$> textValueDirective "gzip_types"
polachok/hs-nginx
src/Nginx/Http/Gzip.hs
mit
1,392
0
10
174
293
158
135
25
1
{-# htermination readDec :: String -> [(Int,String)] #-}
ComputationWithBoundedResources/ara-inference
doc/tpdb_trs/Haskell/full_haskell/Prelude_readDec_1.hs
mit
57
0
2
8
3
2
1
1
0
{-# LANGUAGE QuasiQuotes #-} module Text.Enhask.QQ.Select where import Text.Enhask.QQ.Quote main :: IO () main = putStrLn [select|*|]
astynax/enhask
src/Text/Enhask/QQ/Select.hs
mit
137
0
6
20
38
25
13
5
1
-- Approximate rational-degree rotations with irrational-degree -- rotations a that have rational sin a and cos a. -- This approximation can be made arbitrarily close. module Graphics.Perfract.RatRot (RatRot(..), ratRot, rrSin, rrCos) where import Data.Ratio data RatRot = RatRot { rrSin :: !Rational , rrCos :: !Rational } deriving Show ratRot :: Rational -> RatRot ratRot revsCW | revsCW <= -1/2 = error "ratRot revsCW should have revsCW > -1/2" | revsCW > 1/2 = error "ratRot revsCW should have revsCW <= 1/2" | otherwise = RatRot sinThetaApprox cosThetaApprox where theta = -2 * pi * fromRational revsCW :: Double yOverX = tan theta nOverMApprox = yOverX + sqrt (1 + yOverX * yOverX) m = 100 n = round (nOverMApprox * fromIntegral m) nSq = n * n mSq = m * m denom = nSq + mSq sinThetaApprox = (nSq - mSq) % denom cosThetaApprox = (2 * n * m) % denom
dancor/perfract
src/Graphics/Perfract/RatRot.hs
mit
915
0
11
215
269
145
124
25
1
{- | Module : ./GUI/GtkDisprove.hs Description : Gtk Module to enable disproving Theorems Copyright : (c) Simon Ulbricht, Uni Bremen 2010 License : GPLv2 or higher, see LICENSE.txt Maintainer : [email protected] Stability : provisional Portability : portable This module provides a disproving module that checks consistency of inverted theorems. -} module GUI.GtkDisprove (disproveAtNode) where import Graphics.UI.Gtk import Graphics.UI.Gtk.Glade import GUI.GtkUtils import qualified GUI.Glade.NodeChecker as ConsistencyChecker import GUI.GraphTypes import GUI.GraphLogic hiding (openProofStatus) import GUI.GtkConsistencyChecker import Proofs.ConsistencyCheck import Interfaces.GenericATPState (guiDefaultTimeLimit) import Interfaces.DataTypes import Interfaces.Utils (updateNodeProof) import Logic.Logic import Logic.Prover import Static.DevGraph import Static.GTheory import Static.ComputeTheory import qualified Common.OrderedMap as OMap import Common.AS_Annotation import Common.LibName (LibName) import Common.Result import Common.ExtSign import Control.Concurrent (forkIO, killThread) import Control.Concurrent.MVar import Control.Monad (unless) import Data.Graph.Inductive.Graph (LNode) import Data.IORef import qualified Data.Map as Map import Data.List import Data.Maybe {- | this method holds the functionality to convert the nodes goals to the FNode datatype from GUI.GtkConsistencyChecker. The goals are being negated by negate_th and this theory is stored in FNodes DGNodeLab local and global theory. -} showDisproveGUI :: GInfo -> LibEnv -> DGraph -> LNode DGNodeLab -> IO () showDisproveGUI gi le dg (i, lbl) = case globalTheory lbl of Nothing -> error "GtkDisprove.showDisproveGUI(no global theory found)" Just gt@(G_theory _ _ _ _ sens _) -> let fg g th = let l = lbl { dgn_theory = th } l' = l { globalTheory = computeLabelTheory le dg (i, l) } no_cs = ConsistencyStatus CSUnchecked "" stat = case OMap.lookup g sens of Nothing -> no_cs Just tm -> case thmStatus tm of [] -> no_cs ts -> basicProofToConStatus $ maximum $ map snd ts in FNode { name = g, node = (i, l'), sublogic = sublogicOfTh th, cStatus = stat } fgoals = foldr (\ (g, _) t -> case negate_th gt g of Nothing -> t Just nt -> fg g nt : t) [] $ getThGoals gt in if null fgoals then errorDialogExt "Error (disprove)" "found no goals suitable for disprove function" else do wait <- newEmptyMVar showDisproveWindow wait (libName gi) le dg gt fgoals res <- takeMVar wait runDisproveAtNode gi (i, lbl) res {- | negates a single sentence within a G_theory and returns a theory containing all axioms in addition to the one negated sentence. -} negate_th :: G_theory -> String -> Maybe G_theory negate_th g_th goal = case g_th of G_theory lid1 syn (ExtSign sign symb) i1 sens _ -> case OMap.lookup goal sens of Nothing -> Nothing Just sen -> case negation lid1 $ sentence sen of Nothing -> Nothing Just sen' -> let negSen = sen { sentence = sen', isAxiom = True } sens' = OMap.insert goal negSen $ OMap.filter isAxiom sens in Just $ G_theory lid1 syn (ExtSign sign symb) i1 sens' startThId {- | this function is being called from outside and manages the locking- mechanism of the node being called upon. -} disproveAtNode :: GInfo -> Int -> DGraph -> IO () disproveAtNode gInfo descr dgraph = do lockedEnv <- ensureLockAtNode gInfo descr dgraph case lockedEnv of Nothing -> return () Just (dg, lbl, le) -> do acquired <- tryLockLocal lbl if acquired then do showDisproveGUI gInfo le dg (descr, lbl) unlockLocal lbl else errorDialogExt "Error" "Proof or disproof window already open" {- | after results have been collected, this function is called to store the results for this node within the dgraphs history. -} runDisproveAtNode :: GInfo -> LNode DGNodeLab -> Result G_theory -> IO () runDisproveAtNode gInfo (v, dgnode) (Result ds mres) = case mres of Just rTh -> let oldTh = dgn_theory dgnode in unless (rTh == oldTh) $ do showDiagMessAux 2 ds lockGlobal gInfo let ln = libName gInfo iSt = intState gInfo ost <- readIORef iSt let (ost', hist) = updateNodeProof ln ost (v, dgnode) rTh case i_state ost' of Nothing -> return () Just _ -> do writeIORef iSt ost' runAndLock gInfo $ updateGraph gInfo hist unlockGlobal gInfo _ -> return () {- | Displays a GUI to set TimeoutLimit and select the ConsistencyChecker and holds the functionality to call the ConsistencyChecker for the (previously negated) selected Theorems. -} showDisproveWindow :: MVar (Result G_theory) -> LibName -> LibEnv -> DGraph -> G_theory -> [FNode] -> IO () showDisproveWindow res ln le dg g_th fgoals = postGUIAsync $ do xml <- getGladeXML ConsistencyChecker.get -- get objects window <- xmlGetWidget xml castToWindow "NodeChecker" btnClose <- xmlGetWidget xml castToButton "btnClose" btnResults <- xmlGetWidget xml castToButton "btnResults" -- get goals view and buttons trvGoals <- xmlGetWidget xml castToTreeView "trvNodes" btnNodesAll <- xmlGetWidget xml castToButton "btnNodesAll" btnNodesNone <- xmlGetWidget xml castToButton "btnNodesNone" btnNodesInvert <- xmlGetWidget xml castToButton "btnNodesInvert" btnNodesUnchecked <- xmlGetWidget xml castToButton "btnNodesUnchecked" btnNodesTimeout <- xmlGetWidget xml castToButton "btnNodesTimeout" cbInclThms <- xmlGetWidget xml castToCheckButton "cbInclThms" -- get checker view and buttons cbComorphism <- xmlGetWidget xml castToComboBox "cbComorphism" lblSublogic <- xmlGetWidget xml castToLabel "lblSublogic" sbTimeout <- xmlGetWidget xml castToSpinButton "sbTimeout" btnCheck <- xmlGetWidget xml castToButton "btnCheck" btnStop <- xmlGetWidget xml castToButton "btnStop" trvFinder <- xmlGetWidget xml castToTreeView "trvFinder" toolLabel <- xmlGetWidget xml castToLabel "label1" labelSetLabel toolLabel "Pick disprover" windowSetTitle window "Disprove" spinButtonSetValue sbTimeout $ fromIntegral guiDefaultTimeLimit let widgets = [ toWidget sbTimeout , toWidget cbComorphism , toWidget lblSublogic ] checkWidgets = widgets ++ [ toWidget btnClose , toWidget btnNodesAll , toWidget btnNodesNone , toWidget btnNodesInvert , toWidget btnNodesUnchecked , toWidget btnNodesTimeout , toWidget btnResults ] switch b = do widgetSetSensitive btnStop $ not b widgetSetSensitive btnCheck b widgetSetSensitive btnStop False widgetSetSensitive btnCheck False threadId <- newEmptyMVar wait <- newEmptyMVar mView <- newEmptyMVar -- setup data listGoals <- setListData trvGoals show $ sort fgoals listFinder <- setListData trvFinder fName [] -- setup comorphism combobox comboBoxSetModelText cbComorphism shC <- after cbComorphism changed $ setSelectedComorphism trvFinder listFinder cbComorphism -- setup view selection actions let update = do mf <- getSelectedSingle trvFinder listFinder updateComorphism trvFinder listFinder cbComorphism shC widgetSetSensitive btnCheck $ isJust mf setListSelectorSingle trvFinder update let upd = updateNodes trvGoals listGoals (\ b s -> do labelSetLabel lblSublogic $ show s updateFinder trvFinder listFinder b s) (do labelSetLabel lblSublogic "No sublogic" listStoreClear listFinder activate widgets False widgetSetSensitive btnCheck False) (activate widgets True >> widgetSetSensitive btnCheck True) shN <- setListSelectorMultiple trvGoals btnNodesAll btnNodesNone btnNodesInvert upd -- bindings let selectWithAux f u = do signalBlock shN sel <- treeViewGetSelection trvGoals treeSelectionSelectAll sel rs <- treeSelectionGetSelectedRows sel mapM_ ( \ ~p@(row : []) -> do fn <- listStoreGetValue listGoals row (if f fn then treeSelectionSelectPath else treeSelectionUnselectPath) sel p) rs signalUnblock shN u selectWith f = selectWithAux $ f . cStatus onClicked btnNodesUnchecked $ selectWith (== ConsistencyStatus CSUnchecked "") upd onClicked btnNodesTimeout $ selectWith (== ConsistencyStatus CSTimeout "") upd onClicked btnResults $ showModelView mView "Models" listGoals [] onClicked btnClose $ widgetDestroy window onClicked btnStop $ takeMVar threadId >>= killThread >>= putMVar wait onClicked btnCheck $ do activate checkWidgets False timeout <- spinButtonGetValueAsInt sbTimeout inclThms <- toggleButtonGetActive cbInclThms (updat, pexit) <- progressBar "Checking consistency" "please wait..." goals' <- getSelectedMultiple trvGoals listGoals mf <- getSelectedSingle trvFinder listFinder f <- case mf of Nothing -> error "Disprove: internal error" Just (_, f) -> return f switch False tid <- forkIO $ do {- call the check function from GUI.GtkConsistencyChecker. first argument means disprove-mode and leads the ConsistencyChecker to mark consistent sentences as disproved (since consistent with negated sentence) -} check True inclThms ln le dg f timeout listGoals updat goals' putMVar wait () putMVar threadId tid forkIO_ $ do takeMVar wait postGUIAsync $ do switch True tryTakeMVar threadId showModelView mView "Results of disproving" listGoals [] signalBlock shN sortNodes trvGoals listGoals signalUnblock shN upd activate checkWidgets True pexit {- after window closes a new G_theory is created containing the results. only successful disprove attempts are returned; for each one, a new BasicProof is created and set to disproved. -} onDestroy window $ do fnodes' <- listStoreToList listGoals maybe_F <- getSelectedSingle trvFinder listFinder case maybe_F of Just (_, f) -> case g_th of G_theory lid syn sig i1 sens _ -> let sens' = foldr (\ fg t -> if (sType . cStatus) fg == CSInconsistent then let n' = name fg es = Map.findWithDefault (error "GtkDisprove.showDisproveWindow") n' t s = OMap.ele es ps = openProofStatus n' (fName f) (empty_proof_tree lid) bp = BasicProof lid ps { goalStatus = Disproved } c = comorphism f !! selected f s' = s { senAttr = ThmStatus $ (c, bp) : thmStatus s } in Map.insert n' es { OMap.ele = s' } t else t ) sens fnodes' in putMVar res $ return (G_theory lid syn sig i1 sens' startThId) _ -> putMVar res $ return g_th selectWith (== ConsistencyStatus CSUnchecked "") upd widgetShow window
gnn/Hets
GUI/GtkDisprove.hs
gpl-2.0
11,313
0
33
2,849
2,759
1,316
1,443
-1
-1
module PPDiff ( ColorEnable(..) , ppDiff ) where import Data.Algorithm.Diff (Diff(..)) import System.Console.ANSI data ColorEnable = EnableColor | DisableColor wrap :: ColorEnable -> Color -> String -> String wrap DisableColor _ str = str wrap EnableColor color str = setSGRCode [SetColor Foreground Vivid color] ++ str ++ setSGRCode [Reset] ppDiff :: ColorEnable -> Diff String -> String ppDiff c (First x) = wrap c Red $ '-':x ppDiff c (Second x) = wrap c Green $ '+':x ppDiff c (Both x _) = ' ':x
sinelaw/resolve-trivial-conflicts
PPDiff.hs
gpl-2.0
526
0
9
111
211
112
99
13
1
{-# LANGUAGE CPP #-} {- | Module : ./GUI/GenericATP.hs Description : Generic Prover GUI. Copyright : (c) Thiemo Wiedemeyer, Uni Bremen 2009 License : GPLv2 or higher, see LICENSE.txt Maintainer : [email protected] Stability : provisional Portability : needs POSIX Generic GUI for automatic theorem provers. CPP between HTk and Gtk. -} module GUI.GenericATP (genericATPgui) where import Interfaces.GenericATPState import Logic.Prover #ifdef GTKGLADE import qualified GUI.GtkGenericATP as Gtk #elif defined UNI_PACKAGE import qualified GUI.HTkGenericATP as HTk #endif {- | Invokes the prover GUI. Users may start the batch prover run on all goals, or use a detailed GUI for proving each goal manually. -} genericATPgui :: (Show sentence, Ord proof_tree, Ord sentence) => ATPFunctions sign sentence mor proof_tree pst -- ^ prover specific -- functions -> Bool -- ^ prover supports extra options -> String -- ^ prover name -> String -- ^ theory name -> Theory sign sentence proof_tree {- ^ theory consisting of a signature and a list of Named sentence -} -> [FreeDefMorphism sentence mor] -- ^ freeness constraints -> proof_tree -- ^ initial empty proof_tree -> IO [ProofStatus proof_tree] -- ^ proof status for each goal #ifdef GTKGLADE genericATPgui = Gtk.genericATPgui #elif defined UNI_PACKAGE genericATPgui = HTk.genericATPgui #else genericATPgui = error "not implemented" #endif
spechub/Hets
GUI/GenericATP.hs
gpl-2.0
1,570
0
15
381
142
84
58
14
1
{-# LANGUAGE OverloadedStrings #-} module CV.Projects where import Data.Text import CV.Shared data Project = Project { title :: Text, role :: ProjectRole, homepage :: URI, github :: Maybe Text, pypi :: Maybe Text, dateRange :: DateRange, desc :: Markdown, updates :: [ Update ] } deriving Show data ProjectRole = Creator | CoCreator | Developer | Collaborator | ResearchAssistant deriving Show dh2020 = Venue "Digital Humanities 2020" "https://dh2020.adho.org/" "Ottawa, CA [Virtual]" projects :: [Project] projects = [ Project { title = "Open-Editions", role = Creator, homepage = "https://github.com/open-editions/", github = Just "open-editions/corpus-joyce-ulysses-tei", desc = "Open-source, semantically annotated scholarly editions of literary texts.", dateRange = DateRange (date 2015 09) Present, updates = [ Update (date 2021 01) (Award "Honerable Mention, Emerging Open Scholarship Awards" (Venue "Canadian Social Knowledge Institute" "" "")), Update (date 2020 05) (Publication Article "Open Editions Online (a collaboration with Hans Walter Gabler)" "https://muse.jhu.edu/article/756836" (Venue "James Joyce Quarterly" "https://jjq.utulsa.edu/" "U Tulsa") ), Update (date 2019 01) (Award "Second runner-up, Best DH Data Set" (Venue "2019 DH Awards" "http://dhawards.org/dhawards2019/results/" "")), Update (date 2019 01) (News "[Joycewords.com](http://joycewords.com) released"), Update (date 2018 01) (Talk "Open-Source Scholarly Editions of Works by James Joyce" "" -- TODO: Add URL (Venue "" "" (uni "msu"))), Update (date 2017 10) (Talk "Contributing to the Open Critical Editions of James Joyce" "" -- TODO: Add URL (Venue "Joyce in the Digital Age Conference" "" -- TODO: Add URL (uni "cu"))) ], pypi = Nothing }, Project { title = "Corpus-DB", role = Creator, homepage = "https://github.com/JonathanReeve/corpus-db", github = Just "JonathanReeve/corpus-db", dateRange = DateRange (date 2017 03) Present, desc = "A database and API for plain text archives, for digital humanities research.", updates = [ Update (date 2020 08) (Publication Abstract "Corpus-DB: a Scriptable Textual Corpus Database for Cultural Analytics" "https://dh2020.adho.org/wp-content/uploads/2020/07/604_CorpusDBaScriptableTextualCorpusDatabaseforCulturalAnalytics.html" dh2020), Update (date 2020 07) (Talk "Corpus-DB: a Scriptable Textual Corpus Database for Cultural Analytics" "https://dh2020.adho.org/wp-content/uploads/2020/07/604_CorpusDBaScriptableTextualCorpusDatabaseforCulturalAnalytics.html" dh2020), -- Add CU Libraries talk here? Update (date 2018 01) (Award "micro-grant awarded" (Venue "NYC-DH" "https://nycdh.org/" "")), Update (date 2017 10) (Award "winner" (Venue "2017 NYCDH Graduate Student Project Award" "https://nycdh.org/groups/nycdh-announcements-71439400/forum/topic/2017-nycdh-graduate-student-project-award-recipients/" "")), Update (date 2017 09) (Award "awarded" (Venue "2017 Digital Centers Internship" "" -- TODO: Add URL "Columbia University Libraries" )) ], pypi = Nothing }, Project { title = "Middlemarch Critical Histories", role = CoCreator, homepage = "https://github.com/lit-mod-viz/middlemarch-critical-histories", github= Just "lit-mod-viz/middlemarch-critical-histories", dateRange = DateRange (date 2016 01) Present, desc = "Computational analyses of the critical history of George Eliot's novel _Middlemarch_. In collaboration with Milan Terlunen, Sierra Eckert, Columbia University’s [Group for Experimental Methods in the Humanities](http://xpmethod.plaintext.in/), and the Stanford Literary Lab.", updates = [ Update (date 2017 10) (Publication Abstract "Frequently Cited Passages Across Time: New Methods for Studying the Critical Reception of Texts" "https://github.com/xpmethod/middlemarch-critical-histories/blob/1359d403c8c8655170babb6e1bf8f81bcb4bc0c9/dh2017-submission/middlemarch-abstract.pdf" (Venue "Proceedings of Digital Humanities 2017" "https://dh2017.adho.org/" "Mexico City")), Update (date 2017 08) (Talk "Frequently Cited Passages Across Time: New Methods for Studying the Critical Reception of Texts" "https://github.com/lit-mod-viz/middlemarch-critical-histories/blob/master/papers/dh2017-poster/main.pdf" (Venue "Digital Humanities 2017" "https://dh2017.adho.org/" "Mexico City")), Update (date 2017 02) (Talk "Middlemarch Critical Histories: Initial Findings" "" -- No URI (Venue "Stanford Literary Lab" "" -- TODO: Add url "Stanford University")) ], pypi = Nothing }, Project { title = "Literary Style Transfer", role = Collaborator, desc = "Experiments in the transfer of literary style among genres, using neural networks. A collaboration with Katy Gero, Chris Kedzie, and Lydia Chilton.", dateRange = DateRange (date 2019 05) (date 2019 10), homepage = "https://arxiv.org/abs/1911.03385", github = Nothing, pypi = Nothing, updates = [ Update (date 2019 11) $ Publication Article "Low-Level Linguistic Controls for Style Transfer and Content Preservation" "https://arxiv.org/abs/1911.03385" (Venue "The 12th International Conference on Natural Language Generation" "https://www.inlg2019.com/" "Artificial Intelligence Research Center of Japan") ] }, Project { title = "A Generator of Socratic Dialogues", role = Creator, desc = "A generator of Socratic dialogues, using meta-Markov chains to emulate character speech.", homepage = "http://jonreeve.com/2016/10/socratic-dialogue-generator/", github = Nothing, pypi = Nothing, dateRange = DateRange (date 2016 10) (date 2016 11), updates = [ Update (date 2017 02) (Award "Winner, Best Use of DH For Fun" (Venue "2016 DH Awards" "http://dhawards.org/dhawards2016/results/" "")) ]}, Project { title = "Git-Lit", desc = "A Project to Parse, Version Control, and Publish ~50,000 British Library Electronic Books", role = Creator, pypi = Nothing, github = Nothing, dateRange = DateRange (date 2015 08) (Present), homepage = "https://git-lit.github.io/", updates = [ Update (date 2017 1) (Talk "Git-Lit: an Application of Distributed Version Control Technology Toward the Creation of 50,000 Digital Scholarly Editions" "" (Venue "Modern Language Association Convention" "" "Philadelphia, PA")), Update (date 2016 07) (Award "Winner, student bursary" (Venue "Association of Digital Humanities Organizations" "" "Lausanne, Switzerland")), Update (date 2016 07) (Publication Abstract "Git-Lit: an Application of Distributed Version Control Technology Toward the Creation of 50,000 Digital Scholarly Editions" "http://dh2016.adho.org/abstracts/335" (Venue "Digital Humanities 2016: Conference Abstracts. Jagiellonian University & Pedagogical University, 2016." "http://dh2016.adho.org/static/dh2016_abstracts.pdf" "Kraków, Poland")), Update (date 2016 7) (Talk "Git-Lit: an Application of Distributed Version Control Technology Toward the Creation of 50,000 Digital Scholarly Editions" "" -- Did this have a URL? (Venue "Digital Humanities 2016" "http://dh2016.adho.org/" "Kraków, Poland")), Update (date 2016 04) (Talk "Applications of Distributed Version Control Technology to the Creation of Digital Scholarly Editions" "http://jonreeve.com/presentations/sts2016/" (Venue "Society for Textual Scholarship, Ottawa" "" "")), Update (date 2015 11) (Talk "Git-Lit: An Application of Distributed Version Control Systems Towards the Creation of 50,000 Digital Scholarly Editions" "http://jonreeve.com/presentations/media-res2/" (Venue "Media Res 2" "https://digitalfellows.commons.gc.cuny.edu/2015/11/12/media-res-2-nyc-dh-lightning-talks/" (uni "nyu"))) ] }, Project { title = "Annotags", desc = "A protocol for a literary metadata hashtag that provides the ability to livetweet books, electronic documents, and other texts.", role = Creator, dateRange = DateRange (date 2014 01) (date 2018 01), homepage = "http://annotags.github.io/", github = Just "Annotags/annotags.js", pypi = Nothing, updates = [ Update (date 2015 06) (Award "Featured resource" (Venue "Digital Humanities Now" "http://www.digitalhumanitiesnow.org/2015/07/resource-annotags-a-decentralized-textual-annotation-protocol/" "")), Update (date 2015 06) (Talk "Annotags: A Decentralized Literary Annotation Protocol" "http://www.jonreeve.com/presentations/keydh2015" (Venue "Keystone Digital Humanities conference" "" "")), Update (date 2015 05) (Talk "Annotags: A Decentralized Literary Annotation Protocol" "" (Venue "I Annotate 2015" "http://iannotate.org/" "")), Update (date 2015 02) (Award "Nominated for Best DH Tool" (Venue "DH Awards, 2014" "http://dhawards.org/dhawards2014/results/" "")), Update (date 2014 09) (News "[Web app calculator](/projects/annotags) released") ] }, Project { title = "Chapterize", role = Creator, dateRange = DateRange (date 2016 08) (Present), desc = "A command-line tool for breaking a text into chapters", homepage = "https://github.com/JonathanReeve/chapterize", github = Just "JonathanReeve/chapterize", pypi = Just "chapterize", updates = [] }, Project { title = "Macro-Etymological Text Analysis", role = Creator, desc = "Computational methods applying etymology and language history to textual analysis.", dateRange = DateRange (date 2013 09) (Present), homepage = "http://github.com/JonathanReeve/macro-etym", github = Just "JonathanReeve/macro-etym", pypi = Just "macroetym", updates = [ Update (date 2016 01) $ Publication Chapter "A Macro-Etymological Analysis of James Joyce's A Portrait of the Artist as a Young Man" "https://link.springer.com/chapter/10.1057/978-1-137-59569-0_9" (Venue "Reading Modernism with Machines" "" "Palgrave Macmillan"), Update (date 2015 01) $ News "[Featured](http://www.tapor.ca/?id=470) in the [Text Analysis Portal for Research](http://www.tapor.ca/)", Update (date 2015 01) $ News "Listed in Alain Liu's directory of Digital Humanities Tools", Update (date 2015 03) $ News "Featured in the [Digital Research Tools](http://www.dirtdirectory.org/) (DiRT) directory", Update (date 2015 05) $ News "Released as [a command-line program in the Python Package Archive](https://pypi.python.org/pypi/macroetym)", Update (date 2014 08) $ Award "Winner, student bursary" (Venue "Association of Digital Humanities Organizations" "" "Lausanne, Switzerland"), Update (date 2014 07) $ Award "Winner" (Venue "New York University Hirschhorn Thesis Award" "https://draperprogram.wordpress.com/2014/06/12/congratulations-to-our-hirschhorn-award-nominees-and-winner/" (uni "nyu")), Update (date 2014 04) $ Talk "Macro-Etymological Textual Analysis: a Computational Application of Language History to Literary Criticism" "http://jonreeve.com/presentations/dh2014/" (Venue "Digital Humanities 2014" "http://dh2014.org/" "Lausanne, Switzerland") ] }, Project { title = "Text-Matcher", role = Creator, desc = "Fuzzy text matching and alignment algorithms.", dateRange = DateRange (date 2015 01) (Present), homepage = "http://github.com/JonathanReeve/text-matcher", github = Just "JonathanReeve/text-matcher", pypi = Nothing, updates = [ Update (date 2020 09) $ News "Used in [\"Measuring Unreading,\" a study by Andrew Piper and TxtLab](https://txtlab.org/2020/09/measuring-unreading/)", Update (date 2016 10) $ News "Released [command-line tool on the Python Package Archive](https://pypi.python.org/pypi/text-matcher)", Update (date 2015 05) $ News "Developed for [Modernism, Myth, and their Intertextualities: a Computational Detection of Biblical and Classical Allusion in the English-Language Novel, 1771-1930](https://github.com/JonathanReeve/allusion-detection/blob/master/paper/essay.pdf)" ] }, Project { title = "Customeka", role = Creator, desc = "A highly customizable theme for the Omeka content management system.", dateRange = DateRange (date 2013 01) (date 2015 01), homepage = "http://github.com/JonathanReeve/theme-customeka", github = Just "JonathanReeve/theme-customeka", pypi = Nothing, updates = [ Update (date 2017 01) $ News "Used in the photo archive of the Greenwich Village Society for Historic Preservation", Update (date 2016 08) $ Publication Tutorial "Installing Omeka" "https://programminghistorian.org/en/lessons/installing-omeka" (Venue "The Programming Historian" "https://programminghistorian.org" ""), Update (date 2012 10) $ Talk "Elementaire, a Customizable Omeka Theme" "" (Venue "The Humanities and Technology Camp" "http://newyork2012.thatcamp.org/" "") ] } ]
JonathanReeve/JonathanReeve.github.io
src/CV/Projects.hs
gpl-2.0
15,480
0
15
4,698
2,260
1,227
1,033
223
1
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE LambdaCase #-} ----------------------------------------------------------------------------- -- -- Module : IDE.Metainfo.PackageCollector -- Copyright : 2007-2009 Juergen Nicklisch-Franken, Hamish Mackenzie -- License : GPL Nothing -- -- Maintainer : [email protected] -- Stability : provisional -- Portability : -- -- | -- ----------------------------------------------------------------------------- module IDE.Metainfo.PackageCollector ( collectPackage ) where import Control.Applicative import Prelude import IDE.StrippedPrefs (RetrieveStrategy(..), Prefs(..)) import PackageConfig (PackageConfig) import IDE.Metainfo.SourceCollectorH (findSourceForPackage, packageFromSource, PackageCollectStats(..)) import System.Log.Logger (errorM, debugM, infoM) import IDE.Metainfo.InterfaceCollector (collectPackageFromHI) import IDE.Core.CTypes (metadataVersion, PackageDescr(..), leksahVersion, packageIdentifierToString, getThisPackage, packId) import IDE.Utils.FileUtils (getCollectorPath) import System.Directory (doesDirectoryExist, setCurrentDirectory) import IDE.Utils.Utils (leksahMetadataPathFileExtension, leksahMetadataSystemFileExtension) import System.FilePath (dropFileName, takeBaseName, (<.>), (</>)) import Data.Binary.Shared (encodeFileSer) import Distribution.Text (display) import Control.Monad.IO.Class (MonadIO, MonadIO(..)) import qualified Control.Exception as E (SomeException, catch) import IDE.Utils.Tool (runTool') import Data.Monoid ((<>)) import qualified Data.Text as T (unpack, pack) import Data.Text (Text) import Network.HTTP.Proxy (Proxy(..), fetchProxy) import Network.Browser (request, setAuthorityGen, setOutHandler, setErrHandler, setProxy, browse) import Data.Char (isSpace) import Network.URI (parseURI) import Network.HTTP (rspBody, rspCode, Header(..), Request(..)) import Network.HTTP.Base (RequestMethod(..)) import Network.HTTP.Headers (HeaderName(..)) import qualified Data.ByteString as BS (writeFile, empty) import qualified Paths_leksah_server (version) import Distribution.System (buildArch, buildOS) import Control.Monad (unless) collectPackage :: Bool -> Prefs -> Int -> ((PackageConfig, [FilePath]), Int) -> IO PackageCollectStats collectPackage writeAscii prefs numPackages ((packageConfig, dbs), packageIndex) = do infoM "leksah-server" ("update_toolbar " ++ show ((fromIntegral packageIndex / fromIntegral numPackages) :: Double)) eitherStrFp <- findSourceForPackage prefs pid case eitherStrFp of Left message -> do debugM "leksah-server" . T.unpack $ message <> " : " <> packageName packageDescrHi <- collectPackageFromHI packageConfig dbs writeExtractedPackage False packageDescrHi return stat {packageString = message, modulesTotal = Just (length (pdModules packageDescrHi))} Right fpSource -> case retrieveStrategy prefs of RetrieveThenBuild -> retrieve fpSource >>= \case Just stats -> return stats Nothing -> buildOnly fpSource BuildThenRetrieve -> do debugM "leksah-server" $ "Build (then retrieve) " <> T.unpack packageName <> " in " <> fpSource build fpSource >>= \case (True, bstat) -> return bstat (False, bstat) -> retrieve fpSource >>= \case Just stats -> return stats Nothing -> do packageDescrHi <- collectPackageFromHI packageConfig dbs writeExtractedPackage False packageDescrHi return bstat{modulesTotal = Just (length (pdModules packageDescrHi))} NeverRetrieve -> do debugM "leksah-server" $ "Build " <> T.unpack packageName <> " in " <> fpSource buildOnly fpSource where pid = packId $ getThisPackage packageConfig packageName = packageIdentifierToString pid stat = PackageCollectStats packageName Nothing False False Nothing retrieve :: FilePath -> IO (Maybe PackageCollectStats) retrieve fpSource = do collectorPath <- liftIO getCollectorPath setCurrentDirectory collectorPath let fullUrl = T.unpack (retrieveURL prefs) <> "/metadata-" <> leksahVersion <> "/" <> T.unpack packageName <> leksahMetadataSystemFileExtension filePath = collectorPath </> T.unpack packageName <.> leksahMetadataSystemFileExtension case parseURI fullUrl of Nothing -> do errorM "leksah-server" $ "collectPackage: invalid URI = " <> fullUrl return Nothing Just uri -> do debugM "leksah-server" $ "collectPackage: before retreiving = " <> fullUrl proxy <- filterEmptyProxy . trimProxyUri <$> fetchProxy True (_, rsp) <- browse $ do setProxy proxy setErrHandler (errorM "leksah-server") setOutHandler (debugM "leksah-server") setAuthorityGen (\_ _ -> return Nothing) request Request{ rqURI = uri , rqMethod = GET , rqHeaders = [Header HdrUserAgent userAgent] , rqBody = BS.empty } if rspCode rsp == (2,0,0) then do BS.writeFile filePath $ rspBody rsp debugM "leksah-server" . T.unpack $ "collectPackage: retreived = " <> packageName liftIO $ writePackagePath (dropFileName fpSource) packageName return (Just stat {withSource=True, retrieved= True, mbError=Nothing}) else do debugM "leksah-server" . T.unpack $ "collectPackage: Can't retreive = " <> packageName return Nothing build :: FilePath -> IO (Bool, PackageCollectStats) build fpSource = do runCabalConfigure fpSource mbPackageDescrPair <- packageFromSource fpSource packageConfig case mbPackageDescrPair of (Just packageDescrS, bstat) -> do writePackageDesc packageDescrS fpSource return (True, bstat{modulesTotal = Just (length (pdModules packageDescrS))}) (Nothing, bstat) -> return (False, bstat) buildOnly :: FilePath -> IO PackageCollectStats buildOnly fpSource = build fpSource >>= \case (True, bstat) -> return bstat (False, bstat) -> do packageDescrHi <- collectPackageFromHI packageConfig dbs writeExtractedPackage False packageDescrHi return bstat{modulesTotal = Just (length (pdModules packageDescrHi))} trimProxyUri (Proxy uri auth) = Proxy (trim uri) auth trimProxyUri p = p filterEmptyProxy (Proxy "" _) = NoProxy filterEmptyProxy p = p trim = f . f where f = reverse . dropWhile isSpace userAgent = concat [ "leksah-server/", display Paths_leksah_server.version , " (", display buildOS, "; ", display buildArch, ")" ] writePackageDesc packageDescr fpSource = do liftIO $ writeExtractedPackage writeAscii packageDescr liftIO $ writePackagePath (dropFileName fpSource) packageName runCabalConfigure fpSource = do let dirPath = dropFileName fpSource packageName' = takeBaseName fpSource flagsFor "base" = ["-finteger-gmp2"] flagsFor _ = [] flags = flagsFor packageName' distExists <- doesDirectoryExist $ dirPath </> "dist" unless distExists $ do setCurrentDirectory dirPath E.catch (do runTool' "cabal" ["clean"] Nothing runTool' "cabal" ("configure":flags ++ map (("--package-db"<>) .T.pack) dbs) Nothing return ()) (\ (_e :: E.SomeException) -> do debugM "leksah-server" "Can't configure" return ()) writeExtractedPackage :: MonadIO m => Bool -> PackageDescr -> m () writeExtractedPackage writeAscii pd = do collectorPath <- liftIO getCollectorPath let filePath = collectorPath </> T.unpack (packageIdentifierToString $ pdPackage pd) <.> leksahMetadataSystemFileExtension if writeAscii then liftIO $ writeFile (filePath ++ "dpg") (show pd) else liftIO $ encodeFileSer filePath (metadataVersion, pd) writePackagePath :: MonadIO m => FilePath -> Text -> m () writePackagePath fp packageName = do collectorPath <- liftIO getCollectorPath let filePath = collectorPath </> T.unpack packageName <.> leksahMetadataPathFileExtension liftIO $ writeFile filePath fp
JPMoresmau/leksah-server
src/IDE/Metainfo/PackageCollector.hs
gpl-2.0
9,484
1
32
2,974
2,188
1,139
1,049
163
14
module Graphics.Implicit.Export.Symbolic.Rebound3 (rebound3) where import Graphics.Implicit.Definitions import Data.VectorSpace rebound3 :: BoxedObj3 -> BoxedObj3 rebound3 (obj, (a,b)) = let d :: ℝ3 d = (b ^-^ a) ^/ 10 in (obj, ((a ^-^ d), (b ^+^ d)))
silky/ImplicitCAD
Graphics/Implicit/Export/Symbolic/Rebound3.hs
gpl-2.0
291
0
11
73
107
64
43
9
1
module SpacialGameMsg.SGModelMsg where import System.Random import Data.Maybe import Data.List import qualified PureAgentsPar as PA import qualified Data.Map as Map data SGState = Defector | Cooperator deriving (Eq, Show) data SGMsg = NeighbourPayoff (SGState, Double) | NeighbourState SGState deriving (Eq, Show) data SGAgentState = SIRSAgentState { sgCurrState :: SGState, sgPrevState :: SGState, sgLocalPayoff :: Double, sgBestPayoff :: (SGState, Double), sgNeighbourFlag :: Int } deriving (Show) type SGEnvironment = () type SGAgent = PA.Agent SGMsg SGAgentState SGEnvironment type SGTransformer = PA.AgentTransformer SGMsg SGAgentState SGEnvironment type SGSimHandle = PA.SimHandle SGMsg SGAgentState SGEnvironment bParam :: Double bParam = 1.95 sParam :: Double sParam = 0.0 pParam :: Double pParam = 0.0 rParam :: Double rParam = 1.0 sgTransformer :: SGTransformer sgTransformer (a, ge, le) (_, PA.Domain m) = (sgMsg a m, le) sgTransformer (a, ge, le) (_, PA.Dt dt) = (initialDt a, le) where initialDt :: SGAgent -> SGAgent initialDt a = a' { PA.trans = sgTransformer' } where a' = broadCastLocalState a sgTransformer' :: SGTransformer sgTransformer' (a, ge, le) (_, PA.Dt dt) = (a, le) sgTransformer' (a, ge, le) (_, PA.Domain m) = (sgMsg a m, le) sgMsg :: SGAgent -> SGMsg -> SGAgent sgMsg a (NeighbourState s) = sgStateMsg a s sgMsg a (NeighbourPayoff p) = sgPayoffMsg a p sgStateMsg :: SGAgent -> SGState -> SGAgent sgStateMsg a s = if ( allNeighboursTicked a'' ) then broadCastLocalPayoff a'' else a'' where lp = sgLocalPayoff (PA.state a) poIncrease = payoffWith a s newLp = lp + poIncrease a' = PA.updateState a (\s -> s { sgLocalPayoff = newLp }) a'' = tickNeighbourFlag a' broadCastLocalPayoff :: SGAgent -> SGAgent broadCastLocalPayoff a = resetNeighbourFlag a' where ls = sgCurrState (PA.state a) lp = sgLocalPayoff (PA.state a) a' = PA.broadcastMsgToNeighbours a (NeighbourPayoff (ls, lp)) sgPayoffMsg :: SGAgent -> (SGState, Double) -> SGAgent sgPayoffMsg a p = if ( allNeighboursTicked a'' ) then broadCastLocalState $ switchToBestPayoff a'' else a'' where a' = comparePayoff a p a'' = tickNeighbourFlag a' comparePayoff :: SGAgent -> (SGState, Double) -> SGAgent comparePayoff a p@(_, v) | v > localV = PA.updateState a (\s -> s { sgBestPayoff = p } ) | otherwise = a where (_, localV) = sgBestPayoff (PA.state a) switchToBestPayoff :: SGAgent -> SGAgent switchToBestPayoff a = PA.updateState a (\s -> s { sgCurrState = bestState, sgPrevState = oldState, sgLocalPayoff = 0.0, sgBestPayoff = (bestState, 0.0)} ) where (bestState, _) = sgBestPayoff (PA.state a) oldState = sgCurrState (PA.state a) broadCastLocalState :: SGAgent -> SGAgent broadCastLocalState a = resetNeighbourFlag a' where ls = sgCurrState (PA.state a) a' = PA.broadcastMsgToNeighbours a (NeighbourState ls) -- NOTE: the first state is always the owning agent payoffWith :: SGAgent -> SGState -> Double payoffWith a s = payoff as s where as = sgCurrState (PA.state a) payoff :: SGState -> SGState -> Double payoff Defector Defector = pParam payoff Cooperator Defector = sParam payoff Defector Cooperator = bParam payoff Cooperator Cooperator = rParam allNeighboursTicked :: SGAgent -> Bool allNeighboursTicked a = nf == 0 where nf = (sgNeighbourFlag (PA.state a)) tickNeighbourFlag :: SGAgent -> SGAgent tickNeighbourFlag a = PA.updateState a (\s -> s { sgNeighbourFlag = nf - 1 }) where nf = (sgNeighbourFlag (PA.state a)) resetNeighbourFlag :: SGAgent -> SGAgent resetNeighbourFlag a = PA.updateState a (\s -> s { sgNeighbourFlag = neighbourCount }) where neighbourCount = Map.size (PA.neighbours a) createRandomSGAgents :: StdGen -> (Int, Int) -> Double -> ([SGAgent], StdGen) createRandomSGAgents gInit cells@(x,y) p = (as', g') where n = x * y (randStates, g') = createRandomStates gInit n p as = map (\idx -> PA.createAgent idx (randStates !! idx) sgTransformer) [0..n-1] as' = map (addNeighbours as cells) as createRandomStates :: StdGen -> Int -> Double -> ([SGAgentState], StdGen) createRandomStates g 0 p = ([], g) createRandomStates g n p = (rands, g'') where (randState, g') = randomAgentState g p (ras, g'') = createRandomStates g' (n-1) p rands = randState : ras addNeighbours :: [SGAgent] -> (Int, Int) -> SGAgent -> SGAgent addNeighbours as cells a = resetNeighbourFlag a' where a' = PA.addNeighbours a (agentNeighbours a as cells) setDefector :: [SGAgent] -> (Int, Int) -> (Int, Int) -> [SGAgent] setDefector as pos cells | isNothing mayAgentAtPos = as | otherwise = infront ++ [defectedAgentAtPos] ++ (tail behind) where mayAgentAtPos = find (\a -> pos == (agentToCell a cells)) as agentAtPos = (fromJust mayAgentAtPos) agentAtPosId = PA.agentId agentAtPos defectedAgentAtPos = PA.updateState agentAtPos (\s -> s { sgCurrState = Defector, sgPrevState = Defector, sgBestPayoff = (Defector, 0.0) } ) (infront, behind) = splitAt agentAtPosId as sgEnvironmentFromAgents :: [SGAgent] -> PA.GlobalEnvironment SGEnvironment sgEnvironmentFromAgents as = foldl (\accMap a -> (Map.insert (PA.agentId a) () accMap) ) Map.empty as randomAgentState :: StdGen -> Double -> (SGAgentState, StdGen) randomAgentState g p = (SIRSAgentState{ sgCurrState = s, sgPrevState = s, sgLocalPayoff = 0.0, sgBestPayoff = (s, 0.0), sgNeighbourFlag = -1 }, g') where (isDefector, g') = randomThresh g p s = if isDefector then Defector else Cooperator randomThresh :: StdGen -> Double -> (Bool, StdGen) randomThresh g p = (flag, g') where (thresh, g') = randomR(0.0, 1.0) g flag = thresh <= p agentNeighbours :: SGAgent -> [SGAgent] -> (Int, Int) -> [SGAgent] agentNeighbours a as cells = filter (\a' -> any (==(agentToCell a' cells)) neighbourCells ) as where aCell = agentToCell a cells neighbourCells = neighbours aCell agentToCell :: SGAgent -> (Int, Int) -> (Int, Int) agentToCell a (xCells, yCells) = (ax, ay) where aid = PA.agentId a ax = mod aid yCells ay = floor((fromIntegral aid) / (fromIntegral xCells)) neighbourhood :: [(Int, Int)] neighbourhood = [topLeft, top, topRight, left, center, right, bottomLeft, bottom, bottomRight] where topLeft = (-1, -1) top = (0, -1) topRight = (1, -1) left = (-1, 0) center = (0, 0) right = (1, 0) bottomLeft = (-1, 1) bottom = (0, 1) bottomRight = (1, 1) neighbours :: (Int, Int) -> [(Int, Int)] neighbours (x,y) = map (\(x', y') -> (x+x', y+y')) neighbourhood
thalerjonathan/phd
coding/prototyping/haskell/declarativeABM/haskell/SpatialGameABS/src/SpacialGameMsg/SGModelMsg.hs
gpl-3.0
7,715
0
12
2,402
2,477
1,374
1,103
158
2
Profunctor p => (forall c. p c c) -> p a b
hmemcpy/milewski-ctfp-pdf
src/content/3.10/code/haskell/snippet07.hs
gpl-3.0
42
3
5
11
32
15
17
-1
-1
import System.Environment import qualified Data.Text as T ( pack ) import qualified Data.Text.Lazy as TL ( pack ) import Text.Regex import Text.Regex.Posix import Network.Mail.SMTP data SchoolClass = Inte | Info | Art from = Address Nothing $ T.pack "[email protected]" cc = [ ] bcc = [ ] subject = T.pack "プログラミング愛好会創設に関して" plain to = plainTextPart $ TL.pack $ getBody to "\r\n" html to = htmlPart $ TL.pack $ getBody to "<br />" mail to = simpleMail from [ Address Nothing ( T.pack to ) ] cc bcc subject [ plain to , html to ] getSchoolClass to = case to =~ "^.[123]" of ( _ : "1" ) -> Inte ( _ : "2" ) -> Info ( _ : "3" ) -> Art getBody to crlf = "情報科学部2年の北原です。" ++ crlf ++ "現在「プログラミング愛好会」を設立しようと考えています。" ++ crlf ++ t ++ crlf ++ "興味を持ってくださった方や質問のある方などはこのメールに返信して下さい。よろしくお願いします。" where t = case getSchoolClass to of Inte -> "ITの技術は全世界を繋ぐ技術です、プログラムも国際対応を考えて作らなければならない時代になっています、僕はあなたの力を必要としています。" Info -> "プログラミングは情報技術の中心に常に位置しています、プログラミングを学ぶことはあなたにとってとても重要です。一緒に大学の講義では学べないプログラミングを学びませんか?" Art -> "プログラムの使いやすさ、見た目、全ては芸術に依存しています、僕はあなたの力を必要としています。" main = do ( filePath : _ ) <- getArgs emailsString <- readFile filePath emails <- return $ filter ( /= [ ] ) $ lines emailsString mapM_ ( sendMail "127.0.0.1" . mail ) emails
minamiyama1994/SendMails
SendMails.hs
gpl-3.0
1,898
0
12
253
394
205
189
28
3
{-# OPTIONS_GHC -Wall #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE ExistentialQuantification #-} module Data.RTree.RTree where import Control.Concurrent.STM import qualified Data.Vector as V import qualified Data.RTree.Internal.RTree as I import Data.RTree.Internal.RTree (RInsert(..)) import Data.RTree.TStore data RRoot a = forall h. Root (I.RTree h a) data RTree a = Tree { getConfig :: I.RConfig , getRootVar :: TVar (RRoot a) } defaultEmpty :: STM (RTree a) defaultEmpty = do n <- I.empty rootVar <- newTVar $ Root n return $ Tree I.defaultConfig rootVar upsert :: I.R a => KeyT a -> (a -> a) -> RTree a -> STM () upsert key f (Tree cfg rootVar) = do (Root node) <- readTVar rootVar result <- I.upsert cfg key f node case result of NoExpand -> return () Expand _ -> return () Split bt1 bt2 -> do let nodes = V.fromList [bt1, bt2] tNodes <- newTVar nodes writeTVar rootVar $ Root $ I.Node tNodes
johnpmayer/concurrent-rtree
Data/RTree/RTree.hs
agpl-3.0
961
0
16
207
360
187
173
29
3
module Main where import Graphics.Gloss import Graphics.Gloss.Interface.IO.Game gameUpdatesPerSecond :: Int gameUpdatesPerSecond = 4 windowWidth :: Int windowWidth = 320 windowHeight :: Int windowHeight = 200 windowCaption :: String windowCaption = "Haskell hackathon retro-game by Cats & Dogs" data World = World {} initialWorld :: World initialWorld = World displayWorld :: World -> IO Picture displayWorld _world = return Blank eventHander :: Event -> World -> IO World eventHander _event = return gameUpdateHander :: Float -> World -> IO World gameUpdateHander _timePassedInSeconds = return main :: IO () main = playIO window windowBackgroundColor gameUpdatesPerSecond initialWorld displayWorld eventHander gameUpdateHander where window = InWindow windowCaption (windowWidth, windowHeight) windowTopLeft windowTopLeft = (100,100) windowBackgroundColor = blue
ToJans/retrohackathon
src/Main.hs
unlicense
1,046
12
5
294
209
119
90
35
1
module Utils where import qualified Turtle as Turtle -- import qualified Data.Optional as Optional import qualified Network.AWS.Prelude as AwsPrelude import qualified Text.PrettyPrint.Boxes as Boxes import Aws import qualified Data.List as List import qualified Data.Text as Text -- source: -- http://www.tedreed.info/programming/2012/06/02/how-to-use-textprettyprintboxes/ print_table :: [[String]] -> IO () print_table rows = Boxes.printBox $ Boxes.hsep 2 Boxes.left (map (Boxes.vcat Boxes.left . map Boxes.text) (List.transpose rows)) printSpotPrices :: [HawsSpotPrice] -> IO () printSpotPrices ss = print_table $ headers : fmap toList ss where headers = ["Availability_Zone", "Price", "Instance_Type"] toList :: HawsSpotPrice -> [String] toList HawsSpotPrice{zone=z, priceStr=p, instanceType=t} = fmap Text.unpack [z, p, AwsPrelude.toText t] printSpotPricesScript :: [HawsSpotPrice] -> IO () printSpotPricesScript ss = print_table $ [head $ fmap toList ss] where toList :: HawsSpotPrice -> [String] toList HawsSpotPrice{zone=z, priceStr=p, instanceType=t} = fmap Text.unpack [z, p, AwsPrelude.toText t] printSpotPricesScriptAll :: [HawsSpotPrice] -> IO () printSpotPricesScriptAll ss = print_table $ fmap toList ss where toList :: HawsSpotPrice -> [String] toList HawsSpotPrice{zone=z, priceStr=p, instanceType=t} = fmap Text.unpack [z, p, AwsPrelude.toText t] eitherRead :: Read a => Text.Text -> Either Text.Text a eitherRead t = case reads (Text.unpack t) of [(a, "")] -> Right a _ -> Left (Text.concat ["Cannot parse ", t])
huseyinyilmaz/spotprices
src/Utils.hs
apache-2.0
1,758
0
12
421
538
298
240
32
2
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} module PopVox.Types.Orgs ( OrgContribIndex , OrgContribIndex' , OrgContrib(..) , OrgInfo(..) , orgInfoID , orgInfoName , orgInfoDisposition ) where import Control.Applicative import Control.Lens import Data.Aeson import qualified Data.Aeson as A import Data.Csv hiding ((.:)) import qualified Data.Csv as CSV import Data.Monoid import qualified Data.Text as T import GHC.Generics import PopVox.Types.Common import PopVox.Types.Contrib type OrgContribIndex = HashIndex OrgName ContribIndex type OrgContribIndex' = HashIndex OrgName ContribIndex' data OrgContrib = OrgContrib { orgContribName :: !OrgName , orgDistrict10s :: !T.Text , orgContribEntry :: !ContribEntry , orgContribAmount :: !Amount } deriving (Show, Eq) instance FromNamedRecord OrgContrib where parseNamedRecord m = OrgContrib <$> m CSV..: "contributor_name" <*> m CSV..: "contributor_district_10s" <*> parseNamedRecord m <*> m CSV..: "amount" instance ToNamedRecord OrgContrib where toNamedRecord (OrgContrib n d c a) = namedRecord [ "contributor_name" CSV..= toField n , "contributor_district_10s" CSV..= toField d , "amount" CSV..= toField a ] <> toNamedRecord c data OrgInfo = OrgInfo !OrgID !OrgName !Disposition deriving (Show, Generic) orgInfoID :: Lens' OrgInfo OrgID orgInfoID f (OrgInfo i n d) = fmap (\i' -> OrgInfo i' n d) (f i) orgInfoName :: Lens' OrgInfo OrgName orgInfoName f (OrgInfo i n d) = fmap (\n' -> OrgInfo i n' d) (f n) orgInfoDisposition :: Lens' OrgInfo Disposition orgInfoDisposition f (OrgInfo i n d) = fmap (OrgInfo i n) (f d) instance FromJSON OrgInfo where parseJSON (Object o) = OrgInfo <$> o .: "organization_id" <*> o .: "name" <*> o .: "disposition" parseJSON o = fail $ "Invalid OrgInfo: " ++ show o instance ToJSON OrgInfo where toJSON (OrgInfo i n d) = object [ "organization_id" A..= i , "name" A..= n , "disposition" A..= d ]
erochest/popvox-scrape
src/PopVox/Types/Orgs.hs
apache-2.0
2,603
0
12
980
622
334
288
73
1
{-# OPTIONS -fglasgow-exts #-} ----------------------------------------------------------------------------- {-| Module : QFileDialog_h.hs Copyright : (c) David Harley 2010 Project : qtHaskell Version : 1.1.4 Modified : 2010-09-02 17:02:26 Warning : this file is machine generated - do not modify. --} ----------------------------------------------------------------------------- module Qtc.Gui.QFileDialog_h where import Qtc.Enums.Base import Qtc.Enums.Gui.QPaintDevice import Qtc.Enums.Core.Qt import Qtc.Classes.Base import Qtc.Classes.Qccs_h import Qtc.Classes.Core_h import Qtc.ClassTypes.Core import Qth.ClassTypes.Core import Qtc.Classes.Gui_h import Qtc.ClassTypes.Gui import Foreign.Marshal.Array instance QunSetUserMethod (QFileDialog ()) where unSetUserMethod qobj evid = withBoolResult $ withObjectPtr qobj $ \cobj_qobj -> qtc_QFileDialog_unSetUserMethod cobj_qobj (toCInt 0) (toCInt evid) foreign import ccall "qtc_QFileDialog_unSetUserMethod" qtc_QFileDialog_unSetUserMethod :: Ptr (TQFileDialog a) -> CInt -> CInt -> IO (CBool) instance QunSetUserMethod (QFileDialogSc a) where unSetUserMethod qobj evid = withBoolResult $ withObjectPtr qobj $ \cobj_qobj -> qtc_QFileDialog_unSetUserMethod cobj_qobj (toCInt 0) (toCInt evid) instance QunSetUserMethodVariant (QFileDialog ()) where unSetUserMethodVariant qobj evid = withBoolResult $ withObjectPtr qobj $ \cobj_qobj -> qtc_QFileDialog_unSetUserMethod cobj_qobj (toCInt 1) (toCInt evid) instance QunSetUserMethodVariant (QFileDialogSc a) where unSetUserMethodVariant qobj evid = withBoolResult $ withObjectPtr qobj $ \cobj_qobj -> qtc_QFileDialog_unSetUserMethod cobj_qobj (toCInt 1) (toCInt evid) instance QunSetUserMethodVariantList (QFileDialog ()) where unSetUserMethodVariantList qobj evid = withBoolResult $ withObjectPtr qobj $ \cobj_qobj -> qtc_QFileDialog_unSetUserMethod cobj_qobj (toCInt 2) (toCInt evid) instance QunSetUserMethodVariantList (QFileDialogSc a) where unSetUserMethodVariantList qobj evid = withBoolResult $ withObjectPtr qobj $ \cobj_qobj -> qtc_QFileDialog_unSetUserMethod cobj_qobj (toCInt 2) (toCInt evid) instance QsetUserMethod (QFileDialog ()) (QFileDialog x0 -> IO ()) where setUserMethod _eobj _eid _handler = do funptr <- wrapSetUserMethod_QFileDialog setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetUserMethod_QFileDialog_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> qtc_QFileDialog_setUserMethod cobj_eobj (toCInt _eid) (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return () where setHandlerWrapper :: Ptr (TQFileDialog x0) -> IO () setHandlerWrapper x0 = do x0obj <- objectFromPtr_nf x0 if (objectIsNull x0obj) then return () else _handler x0obj setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setUserMethod" qtc_QFileDialog_setUserMethod :: Ptr (TQFileDialog a) -> CInt -> Ptr (Ptr (TQFileDialog x0) -> IO ()) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetUserMethod_QFileDialog :: (Ptr (TQFileDialog x0) -> IO ()) -> IO (FunPtr (Ptr (TQFileDialog x0) -> IO ())) foreign import ccall "wrapper" wrapSetUserMethod_QFileDialog_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetUserMethod (QFileDialogSc a) (QFileDialog x0 -> IO ()) where setUserMethod _eobj _eid _handler = do funptr <- wrapSetUserMethod_QFileDialog setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetUserMethod_QFileDialog_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> qtc_QFileDialog_setUserMethod cobj_eobj (toCInt _eid) (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return () where setHandlerWrapper :: Ptr (TQFileDialog x0) -> IO () setHandlerWrapper x0 = do x0obj <- objectFromPtr_nf x0 if (objectIsNull x0obj) then return () else _handler x0obj setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance QsetUserMethod (QFileDialog ()) (QFileDialog x0 -> QVariant () -> IO (QVariant ())) where setUserMethod _eobj _eid _handler = do funptr <- wrapSetUserMethodVariant_QFileDialog setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetUserMethodVariant_QFileDialog_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> qtc_QFileDialog_setUserMethodVariant cobj_eobj (toCInt _eid) (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return () where setHandlerWrapper :: Ptr (TQFileDialog x0) -> Ptr (TQVariant ()) -> IO (Ptr (TQVariant ())) setHandlerWrapper x0 x1 = do x0obj <- objectFromPtr_nf x0 x1obj <- objectFromPtr_nf x1 rv <- if (objectIsNull x0obj) then return $ objectCast x0obj else _handler x0obj x1obj withObjectPtr rv $ \cobj_rv -> return cobj_rv setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setUserMethodVariant" qtc_QFileDialog_setUserMethodVariant :: Ptr (TQFileDialog a) -> CInt -> Ptr (Ptr (TQFileDialog x0) -> Ptr (TQVariant ()) -> IO (Ptr (TQVariant ()))) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetUserMethodVariant_QFileDialog :: (Ptr (TQFileDialog x0) -> Ptr (TQVariant ()) -> IO (Ptr (TQVariant ()))) -> IO (FunPtr (Ptr (TQFileDialog x0) -> Ptr (TQVariant ()) -> IO (Ptr (TQVariant ())))) foreign import ccall "wrapper" wrapSetUserMethodVariant_QFileDialog_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetUserMethod (QFileDialogSc a) (QFileDialog x0 -> QVariant () -> IO (QVariant ())) where setUserMethod _eobj _eid _handler = do funptr <- wrapSetUserMethodVariant_QFileDialog setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetUserMethodVariant_QFileDialog_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> qtc_QFileDialog_setUserMethodVariant cobj_eobj (toCInt _eid) (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return () where setHandlerWrapper :: Ptr (TQFileDialog x0) -> Ptr (TQVariant ()) -> IO (Ptr (TQVariant ())) setHandlerWrapper x0 x1 = do x0obj <- objectFromPtr_nf x0 x1obj <- objectFromPtr_nf x1 rv <- if (objectIsNull x0obj) then return $ objectCast x0obj else _handler x0obj x1obj withObjectPtr rv $ \cobj_rv -> return cobj_rv setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance QunSetHandler (QFileDialog ()) where unSetHandler qobj evid = withBoolResult $ withObjectPtr qobj $ \cobj_qobj -> withCWString evid $ \cstr_evid -> qtc_QFileDialog_unSetHandler cobj_qobj cstr_evid foreign import ccall "qtc_QFileDialog_unSetHandler" qtc_QFileDialog_unSetHandler :: Ptr (TQFileDialog a) -> CWString -> IO (CBool) instance QunSetHandler (QFileDialogSc a) where unSetHandler qobj evid = withBoolResult $ withObjectPtr qobj $ \cobj_qobj -> withCWString evid $ \cstr_evid -> qtc_QFileDialog_unSetHandler cobj_qobj cstr_evid instance QsetHandler (QFileDialog ()) (QFileDialog x0 -> QEvent t1 -> IO ()) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog1 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog1_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler1 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> Ptr (TQEvent t1) -> IO () setHandlerWrapper x0 x1 = do x0obj <- qFileDialogFromPtr x0 x1obj <- objectFromPtr_nf x1 if (objectIsNull x0obj) then return () else _handler x0obj x1obj setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setHandler1" qtc_QFileDialog_setHandler1 :: Ptr (TQFileDialog a) -> CWString -> Ptr (Ptr (TQFileDialog x0) -> Ptr (TQEvent t1) -> IO ()) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetHandler_QFileDialog1 :: (Ptr (TQFileDialog x0) -> Ptr (TQEvent t1) -> IO ()) -> IO (FunPtr (Ptr (TQFileDialog x0) -> Ptr (TQEvent t1) -> IO ())) foreign import ccall "wrapper" wrapSetHandler_QFileDialog1_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetHandler (QFileDialogSc a) (QFileDialog x0 -> QEvent t1 -> IO ()) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog1 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog1_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler1 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> Ptr (TQEvent t1) -> IO () setHandlerWrapper x0 x1 = do x0obj <- qFileDialogFromPtr x0 x1obj <- objectFromPtr_nf x1 if (objectIsNull x0obj) then return () else _handler x0obj x1obj setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance QchangeEvent_h (QFileDialog ()) ((QEvent t1)) where changeEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_changeEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_changeEvent" qtc_QFileDialog_changeEvent :: Ptr (TQFileDialog a) -> Ptr (TQEvent t1) -> IO () instance QchangeEvent_h (QFileDialogSc a) ((QEvent t1)) where changeEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_changeEvent cobj_x0 cobj_x1 instance QcloseEvent_h (QFileDialog ()) ((QCloseEvent t1)) where closeEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_closeEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_closeEvent" qtc_QFileDialog_closeEvent :: Ptr (TQFileDialog a) -> Ptr (TQCloseEvent t1) -> IO () instance QcloseEvent_h (QFileDialogSc a) ((QCloseEvent t1)) where closeEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_closeEvent cobj_x0 cobj_x1 instance QcontextMenuEvent_h (QFileDialog ()) ((QContextMenuEvent t1)) where contextMenuEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_contextMenuEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_contextMenuEvent" qtc_QFileDialog_contextMenuEvent :: Ptr (TQFileDialog a) -> Ptr (TQContextMenuEvent t1) -> IO () instance QcontextMenuEvent_h (QFileDialogSc a) ((QContextMenuEvent t1)) where contextMenuEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_contextMenuEvent cobj_x0 cobj_x1 instance QsetHandler (QFileDialog ()) (QFileDialog x0 -> QEvent t1 -> IO (Bool)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog2 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog2_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler2 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> Ptr (TQEvent t1) -> IO (CBool) setHandlerWrapper x0 x1 = do x0obj <- qFileDialogFromPtr x0 x1obj <- objectFromPtr_nf x1 let rv = if (objectIsNull x0obj) then return False else _handler x0obj x1obj rvf <- rv return (toCBool rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setHandler2" qtc_QFileDialog_setHandler2 :: Ptr (TQFileDialog a) -> CWString -> Ptr (Ptr (TQFileDialog x0) -> Ptr (TQEvent t1) -> IO (CBool)) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetHandler_QFileDialog2 :: (Ptr (TQFileDialog x0) -> Ptr (TQEvent t1) -> IO (CBool)) -> IO (FunPtr (Ptr (TQFileDialog x0) -> Ptr (TQEvent t1) -> IO (CBool))) foreign import ccall "wrapper" wrapSetHandler_QFileDialog2_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetHandler (QFileDialogSc a) (QFileDialog x0 -> QEvent t1 -> IO (Bool)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog2 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog2_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler2 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> Ptr (TQEvent t1) -> IO (CBool) setHandlerWrapper x0 x1 = do x0obj <- qFileDialogFromPtr x0 x1obj <- objectFromPtr_nf x1 let rv = if (objectIsNull x0obj) then return False else _handler x0obj x1obj rvf <- rv return (toCBool rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance Qevent_h (QFileDialog ()) ((QEvent t1)) where event_h x0 (x1) = withBoolResult $ withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_event cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_event" qtc_QFileDialog_event :: Ptr (TQFileDialog a) -> Ptr (TQEvent t1) -> IO CBool instance Qevent_h (QFileDialogSc a) ((QEvent t1)) where event_h x0 (x1) = withBoolResult $ withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_event cobj_x0 cobj_x1 instance QkeyPressEvent_h (QFileDialog ()) ((QKeyEvent t1)) where keyPressEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_keyPressEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_keyPressEvent" qtc_QFileDialog_keyPressEvent :: Ptr (TQFileDialog a) -> Ptr (TQKeyEvent t1) -> IO () instance QkeyPressEvent_h (QFileDialogSc a) ((QKeyEvent t1)) where keyPressEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_keyPressEvent cobj_x0 cobj_x1 instance QsetHandler (QFileDialog ()) (QFileDialog x0 -> IO (QSize t0)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog3 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog3_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler3 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> IO (Ptr (TQSize t0)) setHandlerWrapper x0 = do x0obj <- qFileDialogFromPtr x0 let rv = if (objectIsNull x0obj) then return $ objectCast x0obj else _handler x0obj rvf <- rv withObjectPtr rvf $ \cobj_rvf -> return (cobj_rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setHandler3" qtc_QFileDialog_setHandler3 :: Ptr (TQFileDialog a) -> CWString -> Ptr (Ptr (TQFileDialog x0) -> IO (Ptr (TQSize t0))) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetHandler_QFileDialog3 :: (Ptr (TQFileDialog x0) -> IO (Ptr (TQSize t0))) -> IO (FunPtr (Ptr (TQFileDialog x0) -> IO (Ptr (TQSize t0)))) foreign import ccall "wrapper" wrapSetHandler_QFileDialog3_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetHandler (QFileDialogSc a) (QFileDialog x0 -> IO (QSize t0)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog3 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog3_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler3 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> IO (Ptr (TQSize t0)) setHandlerWrapper x0 = do x0obj <- qFileDialogFromPtr x0 let rv = if (objectIsNull x0obj) then return $ objectCast x0obj else _handler x0obj rvf <- rv withObjectPtr rvf $ \cobj_rvf -> return (cobj_rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance QqminimumSizeHint_h (QFileDialog ()) (()) where qminimumSizeHint_h x0 () = withQSizeResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_minimumSizeHint cobj_x0 foreign import ccall "qtc_QFileDialog_minimumSizeHint" qtc_QFileDialog_minimumSizeHint :: Ptr (TQFileDialog a) -> IO (Ptr (TQSize ())) instance QqminimumSizeHint_h (QFileDialogSc a) (()) where qminimumSizeHint_h x0 () = withQSizeResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_minimumSizeHint cobj_x0 instance QminimumSizeHint_h (QFileDialog ()) (()) where minimumSizeHint_h x0 () = withSizeResult $ \csize_ret_w csize_ret_h -> withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_minimumSizeHint_qth cobj_x0 csize_ret_w csize_ret_h foreign import ccall "qtc_QFileDialog_minimumSizeHint_qth" qtc_QFileDialog_minimumSizeHint_qth :: Ptr (TQFileDialog a) -> Ptr CInt -> Ptr CInt -> IO () instance QminimumSizeHint_h (QFileDialogSc a) (()) where minimumSizeHint_h x0 () = withSizeResult $ \csize_ret_w csize_ret_h -> withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_minimumSizeHint_qth cobj_x0 csize_ret_w csize_ret_h instance QsetHandler (QFileDialog ()) (QFileDialog x0 -> IO ()) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog4 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog4_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler4 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> IO () setHandlerWrapper x0 = do x0obj <- qFileDialogFromPtr x0 if (objectIsNull x0obj) then return () else _handler x0obj setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setHandler4" qtc_QFileDialog_setHandler4 :: Ptr (TQFileDialog a) -> CWString -> Ptr (Ptr (TQFileDialog x0) -> IO ()) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetHandler_QFileDialog4 :: (Ptr (TQFileDialog x0) -> IO ()) -> IO (FunPtr (Ptr (TQFileDialog x0) -> IO ())) foreign import ccall "wrapper" wrapSetHandler_QFileDialog4_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetHandler (QFileDialogSc a) (QFileDialog x0 -> IO ()) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog4 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog4_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler4 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> IO () setHandlerWrapper x0 = do x0obj <- qFileDialogFromPtr x0 if (objectIsNull x0obj) then return () else _handler x0obj setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance Qreject_h (QFileDialog ()) (()) where reject_h x0 () = withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_reject cobj_x0 foreign import ccall "qtc_QFileDialog_reject" qtc_QFileDialog_reject :: Ptr (TQFileDialog a) -> IO () instance Qreject_h (QFileDialogSc a) (()) where reject_h x0 () = withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_reject cobj_x0 instance QresizeEvent_h (QFileDialog ()) ((QResizeEvent t1)) where resizeEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_resizeEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_resizeEvent" qtc_QFileDialog_resizeEvent :: Ptr (TQFileDialog a) -> Ptr (TQResizeEvent t1) -> IO () instance QresizeEvent_h (QFileDialogSc a) ((QResizeEvent t1)) where resizeEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_resizeEvent cobj_x0 cobj_x1 instance QsetHandler (QFileDialog ()) (QFileDialog x0 -> Bool -> IO ()) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog5 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog5_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler5 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> CBool -> IO () setHandlerWrapper x0 x1 = do x0obj <- qFileDialogFromPtr x0 let x1bool = fromCBool x1 if (objectIsNull x0obj) then return () else _handler x0obj x1bool setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setHandler5" qtc_QFileDialog_setHandler5 :: Ptr (TQFileDialog a) -> CWString -> Ptr (Ptr (TQFileDialog x0) -> CBool -> IO ()) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetHandler_QFileDialog5 :: (Ptr (TQFileDialog x0) -> CBool -> IO ()) -> IO (FunPtr (Ptr (TQFileDialog x0) -> CBool -> IO ())) foreign import ccall "wrapper" wrapSetHandler_QFileDialog5_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetHandler (QFileDialogSc a) (QFileDialog x0 -> Bool -> IO ()) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog5 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog5_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler5 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> CBool -> IO () setHandlerWrapper x0 x1 = do x0obj <- qFileDialogFromPtr x0 let x1bool = fromCBool x1 if (objectIsNull x0obj) then return () else _handler x0obj x1bool setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance QsetVisible_h (QFileDialog ()) ((Bool)) where setVisible_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_setVisible cobj_x0 (toCBool x1) foreign import ccall "qtc_QFileDialog_setVisible" qtc_QFileDialog_setVisible :: Ptr (TQFileDialog a) -> CBool -> IO () instance QsetVisible_h (QFileDialogSc a) ((Bool)) where setVisible_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_setVisible cobj_x0 (toCBool x1) instance QshowEvent_h (QFileDialog ()) ((QShowEvent t1)) where showEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_showEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_showEvent" qtc_QFileDialog_showEvent :: Ptr (TQFileDialog a) -> Ptr (TQShowEvent t1) -> IO () instance QshowEvent_h (QFileDialogSc a) ((QShowEvent t1)) where showEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_showEvent cobj_x0 cobj_x1 instance QqsizeHint_h (QFileDialog ()) (()) where qsizeHint_h x0 () = withQSizeResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_sizeHint cobj_x0 foreign import ccall "qtc_QFileDialog_sizeHint" qtc_QFileDialog_sizeHint :: Ptr (TQFileDialog a) -> IO (Ptr (TQSize ())) instance QqsizeHint_h (QFileDialogSc a) (()) where qsizeHint_h x0 () = withQSizeResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_sizeHint cobj_x0 instance QsizeHint_h (QFileDialog ()) (()) where sizeHint_h x0 () = withSizeResult $ \csize_ret_w csize_ret_h -> withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_sizeHint_qth cobj_x0 csize_ret_w csize_ret_h foreign import ccall "qtc_QFileDialog_sizeHint_qth" qtc_QFileDialog_sizeHint_qth :: Ptr (TQFileDialog a) -> Ptr CInt -> Ptr CInt -> IO () instance QsizeHint_h (QFileDialogSc a) (()) where sizeHint_h x0 () = withSizeResult $ \csize_ret_w csize_ret_h -> withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_sizeHint_qth cobj_x0 csize_ret_w csize_ret_h instance QactionEvent_h (QFileDialog ()) ((QActionEvent t1)) where actionEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_actionEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_actionEvent" qtc_QFileDialog_actionEvent :: Ptr (TQFileDialog a) -> Ptr (TQActionEvent t1) -> IO () instance QactionEvent_h (QFileDialogSc a) ((QActionEvent t1)) where actionEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_actionEvent cobj_x0 cobj_x1 instance QsetHandler (QFileDialog ()) (QFileDialog x0 -> IO (Int)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog6 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog6_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler6 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> IO (CInt) setHandlerWrapper x0 = do x0obj <- qFileDialogFromPtr x0 let rv = if (objectIsNull x0obj) then return 0 else _handler x0obj rvf <- rv return (toCInt rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setHandler6" qtc_QFileDialog_setHandler6 :: Ptr (TQFileDialog a) -> CWString -> Ptr (Ptr (TQFileDialog x0) -> IO (CInt)) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetHandler_QFileDialog6 :: (Ptr (TQFileDialog x0) -> IO (CInt)) -> IO (FunPtr (Ptr (TQFileDialog x0) -> IO (CInt))) foreign import ccall "wrapper" wrapSetHandler_QFileDialog6_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetHandler (QFileDialogSc a) (QFileDialog x0 -> IO (Int)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog6 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog6_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler6 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> IO (CInt) setHandlerWrapper x0 = do x0obj <- qFileDialogFromPtr x0 let rv = if (objectIsNull x0obj) then return 0 else _handler x0obj rvf <- rv return (toCInt rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance QdevType_h (QFileDialog ()) (()) where devType_h x0 () = withIntResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_devType cobj_x0 foreign import ccall "qtc_QFileDialog_devType" qtc_QFileDialog_devType :: Ptr (TQFileDialog a) -> IO CInt instance QdevType_h (QFileDialogSc a) (()) where devType_h x0 () = withIntResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_devType cobj_x0 instance QdragEnterEvent_h (QFileDialog ()) ((QDragEnterEvent t1)) where dragEnterEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_dragEnterEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_dragEnterEvent" qtc_QFileDialog_dragEnterEvent :: Ptr (TQFileDialog a) -> Ptr (TQDragEnterEvent t1) -> IO () instance QdragEnterEvent_h (QFileDialogSc a) ((QDragEnterEvent t1)) where dragEnterEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_dragEnterEvent cobj_x0 cobj_x1 instance QdragLeaveEvent_h (QFileDialog ()) ((QDragLeaveEvent t1)) where dragLeaveEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_dragLeaveEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_dragLeaveEvent" qtc_QFileDialog_dragLeaveEvent :: Ptr (TQFileDialog a) -> Ptr (TQDragLeaveEvent t1) -> IO () instance QdragLeaveEvent_h (QFileDialogSc a) ((QDragLeaveEvent t1)) where dragLeaveEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_dragLeaveEvent cobj_x0 cobj_x1 instance QdragMoveEvent_h (QFileDialog ()) ((QDragMoveEvent t1)) where dragMoveEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_dragMoveEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_dragMoveEvent" qtc_QFileDialog_dragMoveEvent :: Ptr (TQFileDialog a) -> Ptr (TQDragMoveEvent t1) -> IO () instance QdragMoveEvent_h (QFileDialogSc a) ((QDragMoveEvent t1)) where dragMoveEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_dragMoveEvent cobj_x0 cobj_x1 instance QdropEvent_h (QFileDialog ()) ((QDropEvent t1)) where dropEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_dropEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_dropEvent" qtc_QFileDialog_dropEvent :: Ptr (TQFileDialog a) -> Ptr (TQDropEvent t1) -> IO () instance QdropEvent_h (QFileDialogSc a) ((QDropEvent t1)) where dropEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_dropEvent cobj_x0 cobj_x1 instance QenterEvent_h (QFileDialog ()) ((QEvent t1)) where enterEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_enterEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_enterEvent" qtc_QFileDialog_enterEvent :: Ptr (TQFileDialog a) -> Ptr (TQEvent t1) -> IO () instance QenterEvent_h (QFileDialogSc a) ((QEvent t1)) where enterEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_enterEvent cobj_x0 cobj_x1 instance QfocusInEvent_h (QFileDialog ()) ((QFocusEvent t1)) where focusInEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_focusInEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_focusInEvent" qtc_QFileDialog_focusInEvent :: Ptr (TQFileDialog a) -> Ptr (TQFocusEvent t1) -> IO () instance QfocusInEvent_h (QFileDialogSc a) ((QFocusEvent t1)) where focusInEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_focusInEvent cobj_x0 cobj_x1 instance QfocusOutEvent_h (QFileDialog ()) ((QFocusEvent t1)) where focusOutEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_focusOutEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_focusOutEvent" qtc_QFileDialog_focusOutEvent :: Ptr (TQFileDialog a) -> Ptr (TQFocusEvent t1) -> IO () instance QfocusOutEvent_h (QFileDialogSc a) ((QFocusEvent t1)) where focusOutEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_focusOutEvent cobj_x0 cobj_x1 instance QsetHandler (QFileDialog ()) (QFileDialog x0 -> Int -> IO (Int)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog7 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog7_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler7 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> CInt -> IO (CInt) setHandlerWrapper x0 x1 = do x0obj <- qFileDialogFromPtr x0 let x1int = fromCInt x1 let rv = if (objectIsNull x0obj) then return 0 else _handler x0obj x1int rvf <- rv return (toCInt rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setHandler7" qtc_QFileDialog_setHandler7 :: Ptr (TQFileDialog a) -> CWString -> Ptr (Ptr (TQFileDialog x0) -> CInt -> IO (CInt)) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetHandler_QFileDialog7 :: (Ptr (TQFileDialog x0) -> CInt -> IO (CInt)) -> IO (FunPtr (Ptr (TQFileDialog x0) -> CInt -> IO (CInt))) foreign import ccall "wrapper" wrapSetHandler_QFileDialog7_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetHandler (QFileDialogSc a) (QFileDialog x0 -> Int -> IO (Int)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog7 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog7_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler7 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> CInt -> IO (CInt) setHandlerWrapper x0 x1 = do x0obj <- qFileDialogFromPtr x0 let x1int = fromCInt x1 let rv = if (objectIsNull x0obj) then return 0 else _handler x0obj x1int rvf <- rv return (toCInt rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance QheightForWidth_h (QFileDialog ()) ((Int)) where heightForWidth_h x0 (x1) = withIntResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_heightForWidth cobj_x0 (toCInt x1) foreign import ccall "qtc_QFileDialog_heightForWidth" qtc_QFileDialog_heightForWidth :: Ptr (TQFileDialog a) -> CInt -> IO CInt instance QheightForWidth_h (QFileDialogSc a) ((Int)) where heightForWidth_h x0 (x1) = withIntResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_heightForWidth cobj_x0 (toCInt x1) instance QhideEvent_h (QFileDialog ()) ((QHideEvent t1)) where hideEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_hideEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_hideEvent" qtc_QFileDialog_hideEvent :: Ptr (TQFileDialog a) -> Ptr (TQHideEvent t1) -> IO () instance QhideEvent_h (QFileDialogSc a) ((QHideEvent t1)) where hideEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_hideEvent cobj_x0 cobj_x1 instance QsetHandler (QFileDialog ()) (QFileDialog x0 -> InputMethodQuery -> IO (QVariant t0)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog8 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog8_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler8 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> CLong -> IO (Ptr (TQVariant t0)) setHandlerWrapper x0 x1 = do x0obj <- qFileDialogFromPtr x0 let x1enum = qEnum_fromInt $ fromCLong x1 let rv = if (objectIsNull x0obj) then return $ objectCast x0obj else _handler x0obj x1enum rvf <- rv withObjectPtr rvf $ \cobj_rvf -> return (cobj_rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setHandler8" qtc_QFileDialog_setHandler8 :: Ptr (TQFileDialog a) -> CWString -> Ptr (Ptr (TQFileDialog x0) -> CLong -> IO (Ptr (TQVariant t0))) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetHandler_QFileDialog8 :: (Ptr (TQFileDialog x0) -> CLong -> IO (Ptr (TQVariant t0))) -> IO (FunPtr (Ptr (TQFileDialog x0) -> CLong -> IO (Ptr (TQVariant t0)))) foreign import ccall "wrapper" wrapSetHandler_QFileDialog8_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetHandler (QFileDialogSc a) (QFileDialog x0 -> InputMethodQuery -> IO (QVariant t0)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog8 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog8_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler8 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> CLong -> IO (Ptr (TQVariant t0)) setHandlerWrapper x0 x1 = do x0obj <- qFileDialogFromPtr x0 let x1enum = qEnum_fromInt $ fromCLong x1 let rv = if (objectIsNull x0obj) then return $ objectCast x0obj else _handler x0obj x1enum rvf <- rv withObjectPtr rvf $ \cobj_rvf -> return (cobj_rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance QinputMethodQuery_h (QFileDialog ()) ((InputMethodQuery)) where inputMethodQuery_h x0 (x1) = withQVariantResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_inputMethodQuery cobj_x0 (toCLong $ qEnum_toInt x1) foreign import ccall "qtc_QFileDialog_inputMethodQuery" qtc_QFileDialog_inputMethodQuery :: Ptr (TQFileDialog a) -> CLong -> IO (Ptr (TQVariant ())) instance QinputMethodQuery_h (QFileDialogSc a) ((InputMethodQuery)) where inputMethodQuery_h x0 (x1) = withQVariantResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_inputMethodQuery cobj_x0 (toCLong $ qEnum_toInt x1) instance QkeyReleaseEvent_h (QFileDialog ()) ((QKeyEvent t1)) where keyReleaseEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_keyReleaseEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_keyReleaseEvent" qtc_QFileDialog_keyReleaseEvent :: Ptr (TQFileDialog a) -> Ptr (TQKeyEvent t1) -> IO () instance QkeyReleaseEvent_h (QFileDialogSc a) ((QKeyEvent t1)) where keyReleaseEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_keyReleaseEvent cobj_x0 cobj_x1 instance QleaveEvent_h (QFileDialog ()) ((QEvent t1)) where leaveEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_leaveEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_leaveEvent" qtc_QFileDialog_leaveEvent :: Ptr (TQFileDialog a) -> Ptr (TQEvent t1) -> IO () instance QleaveEvent_h (QFileDialogSc a) ((QEvent t1)) where leaveEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_leaveEvent cobj_x0 cobj_x1 instance QmouseDoubleClickEvent_h (QFileDialog ()) ((QMouseEvent t1)) where mouseDoubleClickEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_mouseDoubleClickEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_mouseDoubleClickEvent" qtc_QFileDialog_mouseDoubleClickEvent :: Ptr (TQFileDialog a) -> Ptr (TQMouseEvent t1) -> IO () instance QmouseDoubleClickEvent_h (QFileDialogSc a) ((QMouseEvent t1)) where mouseDoubleClickEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_mouseDoubleClickEvent cobj_x0 cobj_x1 instance QmouseMoveEvent_h (QFileDialog ()) ((QMouseEvent t1)) where mouseMoveEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_mouseMoveEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_mouseMoveEvent" qtc_QFileDialog_mouseMoveEvent :: Ptr (TQFileDialog a) -> Ptr (TQMouseEvent t1) -> IO () instance QmouseMoveEvent_h (QFileDialogSc a) ((QMouseEvent t1)) where mouseMoveEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_mouseMoveEvent cobj_x0 cobj_x1 instance QmousePressEvent_h (QFileDialog ()) ((QMouseEvent t1)) where mousePressEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_mousePressEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_mousePressEvent" qtc_QFileDialog_mousePressEvent :: Ptr (TQFileDialog a) -> Ptr (TQMouseEvent t1) -> IO () instance QmousePressEvent_h (QFileDialogSc a) ((QMouseEvent t1)) where mousePressEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_mousePressEvent cobj_x0 cobj_x1 instance QmouseReleaseEvent_h (QFileDialog ()) ((QMouseEvent t1)) where mouseReleaseEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_mouseReleaseEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_mouseReleaseEvent" qtc_QFileDialog_mouseReleaseEvent :: Ptr (TQFileDialog a) -> Ptr (TQMouseEvent t1) -> IO () instance QmouseReleaseEvent_h (QFileDialogSc a) ((QMouseEvent t1)) where mouseReleaseEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_mouseReleaseEvent cobj_x0 cobj_x1 instance QmoveEvent_h (QFileDialog ()) ((QMoveEvent t1)) where moveEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_moveEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_moveEvent" qtc_QFileDialog_moveEvent :: Ptr (TQFileDialog a) -> Ptr (TQMoveEvent t1) -> IO () instance QmoveEvent_h (QFileDialogSc a) ((QMoveEvent t1)) where moveEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_moveEvent cobj_x0 cobj_x1 instance QsetHandler (QFileDialog ()) (QFileDialog x0 -> IO (QPaintEngine t0)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog9 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog9_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler9 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> IO (Ptr (TQPaintEngine t0)) setHandlerWrapper x0 = do x0obj <- qFileDialogFromPtr x0 let rv = if (objectIsNull x0obj) then return $ objectCast x0obj else _handler x0obj rvf <- rv withObjectPtr rvf $ \cobj_rvf -> return (cobj_rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () foreign import ccall "qtc_QFileDialog_setHandler9" qtc_QFileDialog_setHandler9 :: Ptr (TQFileDialog a) -> CWString -> Ptr (Ptr (TQFileDialog x0) -> IO (Ptr (TQPaintEngine t0))) -> Ptr () -> Ptr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO () foreign import ccall "wrapper" wrapSetHandler_QFileDialog9 :: (Ptr (TQFileDialog x0) -> IO (Ptr (TQPaintEngine t0))) -> IO (FunPtr (Ptr (TQFileDialog x0) -> IO (Ptr (TQPaintEngine t0)))) foreign import ccall "wrapper" wrapSetHandler_QFileDialog9_d :: (Ptr fun -> Ptr state -> Ptr fun_d -> IO ()) -> IO (FunPtr (Ptr fun -> Ptr state -> Ptr fun_d -> IO ())) instance QsetHandler (QFileDialogSc a) (QFileDialog x0 -> IO (QPaintEngine t0)) where setHandler _eobj _eid _handler = do funptr <- wrapSetHandler_QFileDialog9 setHandlerWrapper stptr <- newStablePtr (Wrap _handler) funptr_d <- wrapSetHandler_QFileDialog9_d setHandlerWrapper_d withObjectPtr _eobj $ \cobj_eobj -> withCWString _eid $ \cstr_eid -> qtc_QFileDialog_setHandler9 cobj_eobj cstr_eid (toCFunPtr funptr) (castStablePtrToPtr stptr) (toCFunPtr funptr_d) return() where setHandlerWrapper :: Ptr (TQFileDialog x0) -> IO (Ptr (TQPaintEngine t0)) setHandlerWrapper x0 = do x0obj <- qFileDialogFromPtr x0 let rv = if (objectIsNull x0obj) then return $ objectCast x0obj else _handler x0obj rvf <- rv withObjectPtr rvf $ \cobj_rvf -> return (cobj_rvf) setHandlerWrapper_d :: Ptr fun -> Ptr () -> Ptr fun_d -> IO () setHandlerWrapper_d funptr stptr funptr_d = do when (stptr/=ptrNull) (freeStablePtr (castPtrToStablePtr stptr)) when (funptr/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr)) when (funptr_d/=ptrNull) (freeHaskellFunPtr (castPtrToFunPtr funptr_d)) return () instance QpaintEngine_h (QFileDialog ()) (()) where paintEngine_h x0 () = withObjectRefResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_paintEngine cobj_x0 foreign import ccall "qtc_QFileDialog_paintEngine" qtc_QFileDialog_paintEngine :: Ptr (TQFileDialog a) -> IO (Ptr (TQPaintEngine ())) instance QpaintEngine_h (QFileDialogSc a) (()) where paintEngine_h x0 () = withObjectRefResult $ withObjectPtr x0 $ \cobj_x0 -> qtc_QFileDialog_paintEngine cobj_x0 instance QpaintEvent_h (QFileDialog ()) ((QPaintEvent t1)) where paintEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_paintEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_paintEvent" qtc_QFileDialog_paintEvent :: Ptr (TQFileDialog a) -> Ptr (TQPaintEvent t1) -> IO () instance QpaintEvent_h (QFileDialogSc a) ((QPaintEvent t1)) where paintEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_paintEvent cobj_x0 cobj_x1 instance QtabletEvent_h (QFileDialog ()) ((QTabletEvent t1)) where tabletEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_tabletEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_tabletEvent" qtc_QFileDialog_tabletEvent :: Ptr (TQFileDialog a) -> Ptr (TQTabletEvent t1) -> IO () instance QtabletEvent_h (QFileDialogSc a) ((QTabletEvent t1)) where tabletEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_tabletEvent cobj_x0 cobj_x1 instance QwheelEvent_h (QFileDialog ()) ((QWheelEvent t1)) where wheelEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_wheelEvent cobj_x0 cobj_x1 foreign import ccall "qtc_QFileDialog_wheelEvent" qtc_QFileDialog_wheelEvent :: Ptr (TQFileDialog a) -> Ptr (TQWheelEvent t1) -> IO () instance QwheelEvent_h (QFileDialogSc a) ((QWheelEvent t1)) where wheelEvent_h x0 (x1) = withObjectPtr x0 $ \cobj_x0 -> withObjectPtr x1 $ \cobj_x1 -> qtc_QFileDialog_wheelEvent cobj_x0 cobj_x1
uduki/hsQt
Qtc/Gui/QFileDialog_h.hs
bsd-2-clause
56,474
0
18
11,967
18,436
8,896
9,540
-1
-1
{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE UndecidableInstances #-} {-| Module : Grenade.Core.Shape Description : Dependently typed shapes of data which are passed between layers of a network Copyright : (c) Huw Campbell, 2016-2017 License : BSD2 Stability : experimental -} module Grenade.Core.Shape ( S (..) , Shape (..) #if MIN_VERSION_singletons(2,6,0) , SShape (..) #else , Sing (..) #endif , randomOfShape , fromStorable ) where import Control.DeepSeq (NFData (..)) import Control.Monad.Random ( MonadRandom, getRandom ) #if MIN_VERSION_base(4,13,0) import Data.Kind (Type) #endif import Data.Proxy import Data.Serialize import Data.Singletons import Data.Singletons.TypeLits import Data.Vector.Storable ( Vector ) import qualified Data.Vector.Storable as V #if MIN_VERSION_base(4,11,0) import GHC.TypeLits hiding (natVal) #else import GHC.TypeLits #endif import qualified Numeric.LinearAlgebra.Static as H import Numeric.LinearAlgebra.Static import qualified Numeric.LinearAlgebra as NLA -- | The current shapes we accept. -- at the moment this is just one, two, and three dimensional -- Vectors/Matricies. -- -- These are only used with DataKinds, as Kind `Shape`, with Types 'D1, 'D2, 'D3. data Shape = D1 Nat -- ^ One dimensional vector | D2 Nat Nat -- ^ Two dimensional matrix. Row, Column. | D3 Nat Nat Nat -- ^ Three dimensional matrix. Row, Column, Channels. -- | Concrete data structures for a Shape. -- -- All shapes are held in contiguous memory. -- 3D is held in a matrix (usually row oriented) which has height depth * rows. data S (n :: Shape) where S1D :: ( KnownNat len ) => R len -> S ('D1 len) S2D :: ( KnownNat rows, KnownNat columns ) => L rows columns -> S ('D2 rows columns) S3D :: ( KnownNat rows , KnownNat columns , KnownNat depth , KnownNat (rows * depth)) => L (rows * depth) columns -> S ('D3 rows columns depth) deriving instance Show (S n) -- Singleton instances. -- -- These could probably be derived with template haskell, but this seems -- clear and makes adding the KnownNat constraints simple. -- We can also keep our code TH free, which is great. #if MIN_VERSION_singletons(2,6,0) -- In singletons 2.6 Sing switched from a data family to a type family. type instance Sing = SShape data SShape :: Shape -> Type where D1Sing :: Sing a -> SShape ('D1 a) D2Sing :: Sing a -> Sing b -> SShape ('D2 a b) D3Sing :: KnownNat (a * c) => Sing a -> Sing b -> Sing c -> SShape ('D3 a b c) #else data instance Sing (n :: Shape) where D1Sing :: Sing a -> Sing ('D1 a) D2Sing :: Sing a -> Sing b -> Sing ('D2 a b) D3Sing :: KnownNat (a * c) => Sing a -> Sing b -> Sing c -> Sing ('D3 a b c) #endif instance KnownNat a => SingI ('D1 a) where sing = D1Sing sing instance (KnownNat a, KnownNat b) => SingI ('D2 a b) where sing = D2Sing sing sing instance (KnownNat a, KnownNat b, KnownNat c, KnownNat (a * c)) => SingI ('D3 a b c) where sing = D3Sing sing sing sing instance SingI x => Num (S x) where (+) = n2 (+) (-) = n2 (-) (*) = n2 (*) abs = n1 abs signum = n1 signum fromInteger x = nk (fromInteger x) instance SingI x => Fractional (S x) where (/) = n2 (/) recip = n1 recip fromRational x = nk (fromRational x) instance SingI x => Floating (S x) where pi = nk pi exp = n1 exp log = n1 log sqrt = n1 sqrt (**) = n2 (**) logBase = n2 logBase sin = n1 sin cos = n1 cos tan = n1 tan asin = n1 asin acos = n1 acos atan = n1 atan sinh = n1 sinh cosh = n1 cosh tanh = n1 tanh asinh = n1 asinh acosh = n1 acosh atanh = n1 atanh -- -- I haven't made shapes strict, as sometimes they're not needed -- (the last input gradient back for instance) -- instance NFData (S x) where rnf (S1D x) = rnf x rnf (S2D x) = rnf x rnf (S3D x) = rnf x -- | Generate random data of the desired shape randomOfShape :: forall x m. ( MonadRandom m, SingI x ) => m (S x) randomOfShape = do seed :: Int <- getRandom return $ case (sing :: Sing x) of D1Sing SNat -> S1D (randomVector seed Uniform * 2 - 1) D2Sing SNat SNat -> S2D (uniformSample seed (-1) 1) D3Sing SNat SNat SNat -> S3D (uniformSample seed (-1) 1) -- | Generate a shape from a Storable Vector. -- -- Returns Nothing if the vector is of the wrong size. fromStorable :: forall x. SingI x => Vector Double -> Maybe (S x) fromStorable xs = case sing :: Sing x of D1Sing SNat -> S1D <$> H.create xs D2Sing SNat SNat -> S2D <$> mkL xs D3Sing SNat SNat SNat -> S3D <$> mkL xs where mkL :: forall rows columns. (KnownNat rows, KnownNat columns) => Vector Double -> Maybe (L rows columns) mkL v = let rows = fromIntegral $ natVal (Proxy :: Proxy rows) columns = fromIntegral $ natVal (Proxy :: Proxy columns) in if rows * columns == V.length v then H.create $ NLA.reshape columns v else Nothing instance SingI x => Serialize (S x) where put i = (case i of (S1D x) -> putListOf put . NLA.toList . H.extract $ x (S2D x) -> putListOf put . NLA.toList . NLA.flatten . H.extract $ x (S3D x) -> putListOf put . NLA.toList . NLA.flatten . H.extract $ x ) :: PutM () get = do Just i <- fromStorable . V.fromList <$> getListOf get return i -- Helper function for creating the number instances n1 :: ( forall a. Floating a => a -> a ) -> S x -> S x n1 f (S1D x) = S1D (f x) n1 f (S2D x) = S2D (f x) n1 f (S3D x) = S3D (f x) -- Helper function for creating the number instances n2 :: ( forall a. Floating a => a -> a -> a ) -> S x -> S x -> S x n2 f (S1D x) (S1D y) = S1D (f x y) n2 f (S2D x) (S2D y) = S2D (f x y) n2 f (S3D x) (S3D y) = S3D (f x y) -- Helper function for creating the number instances nk :: forall x. SingI x => Double -> S x nk x = case (sing :: Sing x) of D1Sing SNat -> S1D (konst x) D2Sing SNat SNat -> S2D (konst x) D3Sing SNat SNat SNat -> S3D (konst x)
HuwCampbell/grenade
src/Grenade/Core/Shape.hs
bsd-2-clause
6,544
0
15
1,794
2,007
1,052
955
142
4
{-# LANGUAGE OverloadedStrings #-} module Network.Sasl.ScramSha1.ScramSha1 ( clientFirstMessageBare, serverFirstMessage, clientFinalMessageWithoutProof, serverFinalMessage, readClientFirstMessage, readServerFirstMessage, readClientFinalMessage, readServerFinalMessage, xo, hash, saltedPassword, clientKey, storedKey, serverKey, clientSignature, clientProof, ) where import Control.Applicative import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as BSC import qualified Data.ByteString.Base64 as B64 import Network.Sasl.ScramSha1.Fields import Network.Sasl.ScramSha1.Functions clientFirstMessageBare :: BS.ByteString -> BS.ByteString -> BS.ByteString clientFirstMessageBare un nnc = BS.concat ["n=", un, ",r=", nnc] serverFirstMessage :: BS.ByteString -> BS.ByteString -> Int -> BS.ByteString serverFirstMessage snnc slt i = BS.concat ["r=", snnc, ",s=", B64.encode slt, ",i=", BSC.pack $ show i] clientFinalMessageWithoutProof :: BS.ByteString -> BS.ByteString -> BS.ByteString clientFinalMessageWithoutProof cb snnc = BS.concat ["c=", B64.encode cb, ",r=", snnc] serverFinalMessage :: BS.ByteString -> BS.ByteString -> BS.ByteString serverFinalMessage sk am = BS.concat ["v=", serverSignature sk am] -- serverSignature (serverKey $ saltedPassword ps slt i) am ] readClientFirstMessage :: BS.ByteString -> Maybe (BS.ByteString, BS.ByteString) readClientFirstMessage rs = case BS.splitAt 3 rs of ("n,,", rs') -> do let kv = readFields rs' (,) <$> lookup "n" kv <*> lookup "r" kv _ -> Nothing readServerFirstMessage :: BS.ByteString -> Maybe (BS.ByteString, BS.ByteString, Int) readServerFirstMessage ch = do let kv = readFields ch (,,) <$> lookup "r" kv <*> ((\(Right r) -> r) . B64.decode <$> lookup "s" kv) <*> (read . BSC.unpack <$> lookup "i" kv) readClientFinalMessage :: BS.ByteString -> Maybe (BS.ByteString, BS.ByteString, BS.ByteString) readClientFinalMessage rs = do let kv = readFields rs (,,) <$> ((\(Right r) -> r) . B64.decode <$> lookup "c" kv) <*> lookup "r" kv <*> ((\(Right r) -> r) . B64.decode <$> lookup "p" kv) readServerFinalMessage :: BS.ByteString -> Maybe BS.ByteString readServerFinalMessage = lookup "v" . readFields
YoshikuniJujo/sasl
src/Network/Sasl/ScramSha1/ScramSha1.hs
bsd-3-clause
2,218
30
16
311
733
398
335
50
2
{-# OPTIONS_GHC -fno-warn-orphans #-} module AI.API.My ( alphabeta , negascout , minimax ) where import Types import Game import AI.Eval import AI.Types import qualified AI.Algorithms.My as Algo alphabeta :: Board b => Evaluation -> Position b -> Depth -> (PV, Score) alphabeta = runAlgo Algo.alphabeta negascout :: Board b => Evaluation -> Position b -> Depth -> (PV, Score) negascout = runAlgo Algo.negascout minimax :: Board b => Evaluation -> Position b -> Depth -> (PV, Score) minimax = runAlgo Algo.minimax instance Board b => Algo.GameTree (Position b) where is_terminal = isOver children = nextPositions runAlgo :: Board b => ((Position b -> Int) -> Depth -> Position b -> (Position b, Score)) -> Evaluation -> Position b -> Depth -> (PV, Score) runAlgo algoFn eval r d = let (r1, score) = algoFn (evalFn eval) d r pv = drop (pMoveNo r) $ reverse (pMoves r1) in (pv, score)
sphynx/hamisado
AI/API/My.hs
bsd-3-clause
938
0
12
206
358
190
168
26
1
module Wyas.Repl where import Wyas.Error import Wyas.Parser import Wyas.Evaluator import Control.Monad (liftM) import System.IO flushStr :: String -> IO () flushStr str = putStr str >> hFlush stdout readPrompt :: String -> IO String readPrompt prompt = flushStr prompt >> getLine evalString :: Env -> String -> IO String evalString env expr = runIOThrows $ liftM show $ (liftThrows $ readExpr expr) >>= eval env evalAndPrint :: Env -> String -> IO () evalAndPrint env expr = evalString env expr >>= putStrLn until_ :: Monad m => (a -> Bool) -> m a -> (a -> m ()) -> m () until_ pred prompt action = do result <- prompt if pred result then return () else action result >> until_ pred prompt action runOne :: String -> IO() runOne expr = nullEnv >>= flip evalAndPrint expr runRepl :: IO () runRepl = nullEnv >>= until_ (== "quit") (readPrompt "LISP>>> ") . evalAndPrint
grtlr/wyas
src/Wyas/Repl.hs
bsd-3-clause
901
0
12
186
358
178
180
24
2
module RSS (getRSSDoc, renderRSS) where import Control.Applicative import qualified Data.ByteString.Lazy.Char8 as LZ import Data.Time import Data.Time.Format (formatTime) import System.Locale (defaultTimeLocale) import Text.Hastache import Text.Hastache.Context import Config import Definition import Entry (formatDate) getRSSDoc :: IO UTCTime -> IO Blog -> IO [Entry] -> IO RSSDoc getRSSDoc = liftA3 feed feed :: UTCTime -> Blog -> [Entry] -> RSSDoc feed now blog entries = let limit = rssLimit blog name = siteName blog desc = metaDescription blog url = baseUrl blog updated = rssDate $ date $ head entries built = rssDate now in RSSDoc (take limit entries) name desc url updated built renderRSS :: Blog -> String -> RSSDoc -> IO () renderRSS blog template rssDoc = hastacheStr defaultConfig (encodeStr template) context >>= writeFeed where context = mkGenericContext rssDoc writeFeed = LZ.writeFile $ get_page_path blog "blog.rss" rssDate :: UTCTime -> String rssDate = formatTime defaultTimeLocale "%B %e, %Y %l:%M %p"
mazelife/agilulf
src/Agiluf/RSS.hs
bsd-3-clause
1,099
0
10
225
329
175
154
28
1
module Options where import CodeGeneration.JavascriptCode -- | Program options data Options = Options { -- | Input HTML inputReader :: IO String, -- | Function that writes the output outputWriter :: String -> IO (), -- | Javascript writing logic javascript :: JavascriptCode }
sergioifg94/Hendoman
src/Options.hs
bsd-3-clause
295
0
11
62
52
32
20
6
0
import Test.Hspec import WordNumber import Cipher import StdFunctions main :: IO () main = hspec $ do describe "myWords" $ do it "single word without prepended space" $ do myWords prependEq prependNEq "all" `shouldBe` ["all"] it "single word with prepended space" $ do myWords prependEq prependNEq " all" `shouldBe` ["all"] it "two word sentence" $ do myWords prependEq prependNEq " all it" `shouldBe` ["all", "it"] it "two word sentence" $ do myWords prependEq prependNEq "all it" `shouldBe` ["all", "it"] describe "cipherChar" $ do it "encodes a character with an offset" $ do cipherChar 1 'a' `shouldBe` 'b' it "encodes a character with an offset with mod" $ do cipherChar 122 'a' `shouldBe` 'b' describe "cipher" $ do it "encodes a message with an offset" $ do cipher 1 "hello" `shouldBe` "ifmmp" it "encodes a whole sentence, correctly" $ do cipher 20 "hi, john! What is going on?" `shouldBe` "\ETX\EOT@4\ENQ\n\ETX\t54k\ETXu\SI4\EOT\SO4\STX\n\EOT\t\STX4\n\tS" describe "myOr" $ do it "myOr will work like or in prelude" $ do myOr [True, True, True, False] `shouldBe` True describe "myAny" $ do it "myAny will work like any in prelude" $ do myAny even [1,2,3] `shouldBe` True describe "myElem" $ do it "myElem works like elem in prelude" $ do myElem 'a' "aeiou" `shouldBe` True describe "myElemAny" $ do it "myElemAny works like myElem, but uses any" $ do myElemAny 'a' "aeiou" `shouldBe` True describe "cipher to unCipher" $ do it "unCipher applied to cipher with give back the same sentence" $ do unCipher 20 msg `shouldBe` "hello, John!" where msg = cipher 20 "hello, John!"
halarnold2000/learnhaskell
test/Spec.hs
bsd-3-clause
1,828
0
16
504
483
229
254
42
1
{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE TemplateHaskell #-} module Example where import Prelude (String, concat, error, otherwise) import Development.GitRev panic :: String -> a panic msg = error panicMsg where panicMsg = concat [ "[panic ", $(gitBranch), "@", $(gitHash) , " (", $(gitCommitDate), ")" , " (", $(gitCommitCount), " commits in HEAD)" , dirty, "] ", msg ] dirty | $(gitDirty) = " (uncommitted files present)" | otherwise = "" main = panic "oh no!"
acfoltzer/gitrev
Example.hs
bsd-3-clause
559
0
11
164
145
83
62
15
1
{- (c) The University of Glasgow 2006-2008 (c) The GRASP/AQUA Project, Glasgow University, 1993-1998 -} {-# LANGUAGE CPP, NondecreasingIndentation #-} -- | Module for constructing @ModIface@ values (interface files), -- writing them to disk and comparing two versions to see if -- recompilation is required. module MkIface ( mkIface, -- Build a ModIface from a ModGuts, -- including computing version information mkIfaceTc, writeIfaceFile, -- Write the interface file checkOldIface, -- See if recompilation is required, by -- comparing version information RecompileRequired(..), recompileRequired, mkIfaceExports, tyThingToIfaceDecl -- Converting things to their Iface equivalents ) where {- ----------------------------------------------- Recompilation checking ----------------------------------------------- A complete description of how recompilation checking works can be found in the wiki commentary: http://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/RecompilationAvoidance Please read the above page for a top-down description of how this all works. Notes below cover specific issues related to the implementation. Basic idea: * In the mi_usages information in an interface, we record the fingerprint of each free variable of the module * In mkIface, we compute the fingerprint of each exported thing A.f. For each external thing that A.f refers to, we include the fingerprint of the external reference when computing the fingerprint of A.f. So if anything that A.f depends on changes, then A.f's fingerprint will change. Also record any dependent files added with * addDependentFile * #include * -optP-include * In checkOldIface we compare the mi_usages for the module with the actual fingerprint for all each thing recorded in mi_usages -} #include "HsVersions.h" import IfaceSyn import LoadIface import FlagChecker import Desugar ( mkUsageInfo, mkUsedNames, mkDependencies ) import Id import IdInfo import Demand import Coercion( tidyCo ) import Annotations import CoreSyn import Class import TyCon import CoAxiom import ConLike import DataCon import PatSyn import Type import TcType import InstEnv import FamInstEnv import TcRnMonad import HsSyn import HscTypes import Finder import DynFlags import VarEnv import VarSet import Var import Name import Avail import RdrName import NameEnv import NameSet import Module import BinIface import ErrUtils import Digraph import SrcLoc import Outputable import BasicTypes hiding ( SuccessFlag(..) ) import Unique import Util hiding ( eqListBy ) import FastString import FastStringEnv import Maybes import Binary import Fingerprint import Exception import UniqFM import UniqDFM import MkId import Control.Monad import Data.Function import Data.List import qualified Data.Map as Map import Data.Ord import Data.IORef import System.Directory import System.FilePath {- ************************************************************************ * * \subsection{Completing an interface} * * ************************************************************************ -} mkIface :: HscEnv -> Maybe Fingerprint -- The old fingerprint, if we have it -> ModDetails -- The trimmed, tidied interface -> ModGuts -- Usages, deprecations, etc -> IO (ModIface, -- The new one Bool) -- True <=> there was an old Iface, and the -- new one is identical, so no need -- to write it mkIface hsc_env maybe_old_fingerprint mod_details ModGuts{ mg_module = this_mod, mg_hsc_src = hsc_src, mg_usages = usages, mg_used_th = used_th, mg_deps = deps, mg_rdr_env = rdr_env, mg_fix_env = fix_env, mg_warns = warns, mg_hpc_info = hpc_info, mg_safe_haskell = safe_mode, mg_trust_pkg = self_trust } = mkIface_ hsc_env maybe_old_fingerprint this_mod hsc_src used_th deps rdr_env fix_env warns hpc_info self_trust safe_mode usages mod_details -- | make an interface from the results of typechecking only. Useful -- for non-optimising compilation, or where we aren't generating any -- object code at all ('HscNothing'). mkIfaceTc :: HscEnv -> Maybe Fingerprint -- The old fingerprint, if we have it -> SafeHaskellMode -- The safe haskell mode -> ModDetails -- gotten from mkBootModDetails, probably -> TcGblEnv -- Usages, deprecations, etc -> IO (ModIface, Bool) mkIfaceTc hsc_env maybe_old_fingerprint safe_mode mod_details tc_result@TcGblEnv{ tcg_mod = this_mod, tcg_semantic_mod = semantic_mod, tcg_src = hsc_src, tcg_imports = imports, tcg_rdr_env = rdr_env, tcg_fix_env = fix_env, tcg_merged = merged, tcg_warns = warns, tcg_hpc = other_hpc_info, tcg_th_splice_used = tc_splice_used, tcg_dependent_files = dependent_files } = do let used_names = mkUsedNames tc_result deps <- mkDependencies tc_result let hpc_info = emptyHpcInfo other_hpc_info used_th <- readIORef tc_splice_used dep_files <- (readIORef dependent_files) usages <- mkUsageInfo hsc_env semantic_mod (imp_mods imports) used_names dep_files merged mkIface_ hsc_env maybe_old_fingerprint this_mod hsc_src used_th deps rdr_env fix_env warns hpc_info (imp_trust_own_pkg imports) safe_mode usages mod_details mkIface_ :: HscEnv -> Maybe Fingerprint -> Module -> HscSource -> Bool -> Dependencies -> GlobalRdrEnv -> NameEnv FixItem -> Warnings -> HpcInfo -> Bool -> SafeHaskellMode -> [Usage] -> ModDetails -> IO (ModIface, Bool) mkIface_ hsc_env maybe_old_fingerprint this_mod hsc_src used_th deps rdr_env fix_env src_warns hpc_info pkg_trust_req safe_mode usages ModDetails{ md_insts = insts, md_fam_insts = fam_insts, md_rules = rules, md_anns = anns, md_vect_info = vect_info, md_types = type_env, md_exports = exports } -- NB: notice that mkIface does not look at the bindings -- only at the TypeEnv. The previous Tidy phase has -- put exactly the info into the TypeEnv that we want -- to expose in the interface = do let semantic_mod = canonicalizeHomeModule (hsc_dflags hsc_env) (moduleName this_mod) entities = typeEnvElts type_env decls = [ tyThingToIfaceDecl entity | entity <- entities, let name = getName entity, not (isImplicitTyThing entity), -- No implicit Ids and class tycons in the interface file not (isWiredInName name), -- Nor wired-in things; the compiler knows about them anyhow nameIsLocalOrFrom semantic_mod name ] -- Sigh: see Note [Root-main Id] in TcRnDriver -- NB: ABSOLUTELY need to check against semantic_mod, -- because all of the names in an hsig p[H=<H>]:H -- are going to be for <H>, not the former id! -- See Note [Identity versus semantic module] fixities = sortBy (comparing fst) [(occ,fix) | FixItem occ fix <- nameEnvElts fix_env] -- The order of fixities returned from nameEnvElts is not -- deterministic, so we sort by OccName to canonicalize it. -- See Note [Deterministic UniqFM] in UniqDFM for more details. warns = src_warns iface_rules = map coreRuleToIfaceRule rules iface_insts = map instanceToIfaceInst $ fixSafeInstances safe_mode insts iface_fam_insts = map famInstToIfaceFamInst fam_insts iface_vect_info = flattenVectInfo vect_info trust_info = setSafeMode safe_mode annotations = map mkIfaceAnnotation anns intermediate_iface = ModIface { mi_module = this_mod, -- Need to record this because it depends on the -instantiated-with flag -- which could change mi_sig_of = if semantic_mod == this_mod then Nothing else Just semantic_mod, mi_hsc_src = hsc_src, mi_deps = deps, mi_usages = usages, mi_exports = mkIfaceExports exports, -- Sort these lexicographically, so that -- the result is stable across compilations mi_insts = sortBy cmp_inst iface_insts, mi_fam_insts = sortBy cmp_fam_inst iface_fam_insts, mi_rules = sortBy cmp_rule iface_rules, mi_vect_info = iface_vect_info, mi_fixities = fixities, mi_warns = warns, mi_anns = annotations, mi_globals = maybeGlobalRdrEnv rdr_env, -- Left out deliberately: filled in by addFingerprints mi_iface_hash = fingerprint0, mi_mod_hash = fingerprint0, mi_flag_hash = fingerprint0, mi_exp_hash = fingerprint0, mi_used_th = used_th, mi_orphan_hash = fingerprint0, mi_orphan = False, -- Always set by addFingerprints, but -- it's a strict field, so we can't omit it. mi_finsts = False, -- Ditto mi_decls = deliberatelyOmitted "decls", mi_hash_fn = deliberatelyOmitted "hash_fn", mi_hpc = isHpcUsed hpc_info, mi_trust = trust_info, mi_trust_pkg = pkg_trust_req, -- And build the cached values mi_warn_fn = mkIfaceWarnCache warns, mi_fix_fn = mkIfaceFixCache fixities } (new_iface, no_change_at_all) <- {-# SCC "versioninfo" #-} addFingerprints hsc_env maybe_old_fingerprint intermediate_iface decls -- Debug printing dumpIfSet_dyn dflags Opt_D_dump_hi "FINAL INTERFACE" (pprModIface new_iface) -- bug #1617: on reload we weren't updating the PrintUnqualified -- correctly. This stems from the fact that the interface had -- not changed, so addFingerprints returns the old ModIface -- with the old GlobalRdrEnv (mi_globals). let final_iface = new_iface{ mi_globals = maybeGlobalRdrEnv rdr_env } return (final_iface, no_change_at_all) where cmp_rule = comparing ifRuleName -- Compare these lexicographically by OccName, *not* by unique, -- because the latter is not stable across compilations: cmp_inst = comparing (nameOccName . ifDFun) cmp_fam_inst = comparing (nameOccName . ifFamInstTcName) dflags = hsc_dflags hsc_env -- We only fill in mi_globals if the module was compiled to byte -- code. Otherwise, the compiler may not have retained all the -- top-level bindings and they won't be in the TypeEnv (see -- Desugar.addExportFlagsAndRules). The mi_globals field is used -- by GHCi to decide whether the module has its full top-level -- scope available. (#5534) maybeGlobalRdrEnv :: GlobalRdrEnv -> Maybe GlobalRdrEnv maybeGlobalRdrEnv rdr_env | targetRetainsAllBindings (hscTarget dflags) = Just rdr_env | otherwise = Nothing deliberatelyOmitted :: String -> a deliberatelyOmitted x = panic ("Deliberately omitted: " ++ x) ifFamInstTcName = ifFamInstFam flattenVectInfo (VectInfo { vectInfoVar = vVar , vectInfoTyCon = vTyCon , vectInfoParallelVars = vParallelVars , vectInfoParallelTyCons = vParallelTyCons }) = IfaceVectInfo { ifaceVectInfoVar = [Var.varName v | (v, _ ) <- dVarEnvElts vVar] , ifaceVectInfoTyCon = [tyConName t | (t, t_v) <- nameEnvElts vTyCon, t /= t_v] , ifaceVectInfoTyConReuse = [tyConName t | (t, t_v) <- nameEnvElts vTyCon, t == t_v] , ifaceVectInfoParallelVars = [Var.varName v | v <- dVarSetElems vParallelVars] , ifaceVectInfoParallelTyCons = nameSetElemsStable vParallelTyCons } ----------------------------- writeIfaceFile :: DynFlags -> FilePath -> ModIface -> IO () writeIfaceFile dflags hi_file_path new_iface = do createDirectoryIfMissing True (takeDirectory hi_file_path) writeBinIface dflags hi_file_path new_iface -- ----------------------------------------------------------------------------- -- Look up parents and versions of Names -- This is like a global version of the mi_hash_fn field in each ModIface. -- Given a Name, it finds the ModIface, and then uses mi_hash_fn to get -- the parent and version info. mkHashFun :: HscEnv -- needed to look up versions -> ExternalPackageState -- ditto -> (Name -> IO Fingerprint) mkHashFun hsc_env eps name | isHoleModule orig_mod = lookup (mkModule (thisPackage dflags) (moduleName orig_mod)) | otherwise = lookup orig_mod where dflags = hsc_dflags hsc_env hpt = hsc_HPT hsc_env pit = eps_PIT eps occ = nameOccName name orig_mod = nameModule name lookup mod = do MASSERT2( isExternalName name, ppr name ) iface <- case lookupIfaceByModule dflags hpt pit mod of Just iface -> return iface Nothing -> do -- This can occur when we're writing out ifaces for -- requirements; we didn't do any /real/ typechecking -- so there's no guarantee everything is loaded. -- Kind of a heinous hack. iface <- initIfaceLoad hsc_env . withException $ loadInterface (text "lookupVers2") mod ImportBySystem return iface return $ snd (mi_hash_fn iface occ `orElse` pprPanic "lookupVers1" (ppr mod <+> ppr occ)) -- --------------------------------------------------------------------------- -- Compute fingerprints for the interface addFingerprints :: HscEnv -> Maybe Fingerprint -- the old fingerprint, if any -> ModIface -- The new interface (lacking decls) -> [IfaceDecl] -- The new decls -> IO (ModIface, -- Updated interface Bool) -- True <=> no changes at all; -- no need to write Iface addFingerprints hsc_env mb_old_fingerprint iface0 new_decls = do eps <- hscEPS hsc_env let -- The ABI of a declaration represents everything that is made -- visible about the declaration that a client can depend on. -- see IfaceDeclABI below. declABI :: IfaceDecl -> IfaceDeclABI -- TODO: I'm not sure if this should be semantic_mod or this_mod. -- See also Note [Identity versus semantic module] declABI decl = (this_mod, decl, extras) where extras = declExtras fix_fn ann_fn non_orph_rules non_orph_insts non_orph_fis decl edges :: [(IfaceDeclABI, Unique, [Unique])] edges = [ (abi, getUnique (ifName decl), out) | decl <- new_decls , let abi = declABI decl , let out = localOccs $ freeNamesDeclABI abi ] name_module n = ASSERT2( isExternalName n, ppr n ) nameModule n localOccs = map (getUnique . getParent . getOccName) -- NB: names always use semantic module, so -- filtering must be on the semantic module! -- See Note [Identity versus semantic module] . filter ((== semantic_mod) . name_module) . nonDetEltsUFM -- It's OK to use nonDetEltsUFM as localOccs is only -- used to construct the edges and -- stronglyConnCompFromEdgedVertices is deterministic -- even with non-deterministic order of edges as -- explained in Note [Deterministic SCC] in Digraph. where getParent occ = lookupOccEnv parent_map occ `orElse` occ -- maps OccNames to their parents in the current module. -- e.g. a reference to a constructor must be turned into a reference -- to the TyCon for the purposes of calculating dependencies. parent_map :: OccEnv OccName parent_map = foldr extend emptyOccEnv new_decls where extend d env = extendOccEnvList env [ (b,n) | b <- ifaceDeclImplicitBndrs d ] where n = ifName d -- strongly-connected groups of declarations, in dependency order groups = stronglyConnCompFromEdgedVerticesUniq edges global_hash_fn = mkHashFun hsc_env eps -- how to output Names when generating the data to fingerprint. -- Here we want to output the fingerprint for each top-level -- Name, whether it comes from the current module or another -- module. In this way, the fingerprint for a declaration will -- change if the fingerprint for anything it refers to (transitively) -- changes. mk_put_name :: (OccEnv (OccName,Fingerprint)) -> BinHandle -> Name -> IO () mk_put_name local_env bh name | isWiredInName name = putNameLiterally bh name -- wired-in names don't have fingerprints | otherwise = ASSERT2( isExternalName name, ppr name ) let hash | nameModule name /= semantic_mod = global_hash_fn name -- Get it from the REAL interface!! -- This will trigger when we compile an hsig file -- and we know a backing impl for it. -- See Note [Identity versus semantic module] | semantic_mod /= this_mod , not (isHoleModule semantic_mod) = global_hash_fn name | otherwise = return (snd (lookupOccEnv local_env (getOccName name) `orElse` pprPanic "urk! lookup local fingerprint" (ppr name))) -- This panic indicates that we got the dependency -- analysis wrong, because we needed a fingerprint for -- an entity that wasn't in the environment. To debug -- it, turn the panic into a trace, uncomment the -- pprTraces below, run the compile again, and inspect -- the output and the generated .hi file with -- --show-iface. in hash >>= put_ bh -- take a strongly-connected group of declarations and compute -- its fingerprint. fingerprint_group :: (OccEnv (OccName,Fingerprint), [(Fingerprint,IfaceDecl)]) -> SCC IfaceDeclABI -> IO (OccEnv (OccName,Fingerprint), [(Fingerprint,IfaceDecl)]) fingerprint_group (local_env, decls_w_hashes) (AcyclicSCC abi) = do let hash_fn = mk_put_name local_env decl = abiDecl abi --pprTrace "fingerprinting" (ppr (ifName decl) ) $ do hash <- computeFingerprint hash_fn abi env' <- extend_hash_env local_env (hash,decl) return (env', (hash,decl) : decls_w_hashes) fingerprint_group (local_env, decls_w_hashes) (CyclicSCC abis) = do let decls = map abiDecl abis local_env1 <- foldM extend_hash_env local_env (zip (repeat fingerprint0) decls) let hash_fn = mk_put_name local_env1 -- pprTrace "fingerprinting" (ppr (map ifName decls) ) $ do let stable_abis = sortBy cmp_abiNames abis -- put the cycle in a canonical order hash <- computeFingerprint hash_fn stable_abis let pairs = zip (repeat hash) decls local_env2 <- foldM extend_hash_env local_env pairs return (local_env2, pairs ++ decls_w_hashes) -- we have fingerprinted the whole declaration, but we now need -- to assign fingerprints to all the OccNames that it binds, to -- use when referencing those OccNames in later declarations. -- extend_hash_env :: OccEnv (OccName,Fingerprint) -> (Fingerprint,IfaceDecl) -> IO (OccEnv (OccName,Fingerprint)) extend_hash_env env0 (hash,d) = do return (foldr (\(b,fp) env -> extendOccEnv env b (b,fp)) env0 (ifaceDeclFingerprints hash d)) -- (local_env, decls_w_hashes) <- foldM fingerprint_group (emptyOccEnv, []) groups -- when calculating fingerprints, we always need to use canonical -- ordering for lists of things. In particular, the mi_deps has various -- lists of modules and suchlike, so put these all in canonical order: let sorted_deps = sortDependencies (mi_deps iface0) -- the export hash of a module depends on the orphan hashes of the -- orphan modules below us in the dependency tree. This is the way -- that changes in orphans get propagated all the way up the -- dependency tree. We only care about orphan modules in the current -- package, because changes to orphans outside this package will be -- tracked by the usage on the ABI hash of package modules that we import. let orph_mods = filter (/= this_mod) -- Note [Do not update EPS with your own hi-boot] . filter ((== this_pkg) . moduleUnitId) $ dep_orphs sorted_deps dep_orphan_hashes <- getOrphanHashes hsc_env orph_mods -- Note [Do not update EPS with your own hi-boot] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- (See also Trac #10182). When your hs-boot file includes an orphan -- instance declaration, you may find that the dep_orphs of a module you -- import contains reference to yourself. DO NOT actually load this module -- or add it to the orphan hashes: you're going to provide the orphan -- instances yourself, no need to consult hs-boot; if you do load the -- interface into EPS, you will see a duplicate orphan instance. orphan_hash <- computeFingerprint (mk_put_name local_env) (map ifDFun orph_insts, orph_rules, orph_fis) -- the export list hash doesn't depend on the fingerprints of -- the Names it mentions, only the Names themselves, hence putNameLiterally. export_hash <- computeFingerprint putNameLiterally (mi_exports iface0, orphan_hash, dep_orphan_hashes, dep_pkgs (mi_deps iface0), -- dep_pkgs: see "Package Version Changes" on -- wiki/Commentary/Compiler/RecompilationAvoidance mi_trust iface0) -- Make sure change of Safe Haskell mode causes recomp. -- put the declarations in a canonical order, sorted by OccName let sorted_decls = Map.elems $ Map.fromList $ [(ifName d, e) | e@(_, d) <- decls_w_hashes] -- the flag hash depends on: -- - (some of) dflags -- it returns two hashes, one that shouldn't change -- the abi hash and one that should flag_hash <- fingerprintDynFlags dflags this_mod putNameLiterally -- the ABI hash depends on: -- - decls -- - export list -- - orphans -- - deprecations -- - vect info -- - flag abi hash mod_hash <- computeFingerprint putNameLiterally (map fst sorted_decls, export_hash, -- includes orphan_hash mi_warns iface0, mi_vect_info iface0) -- The interface hash depends on: -- - the ABI hash, plus -- - the module level annotations, -- - usages -- - deps (home and external packages, dependent files) -- - hpc iface_hash <- computeFingerprint putNameLiterally (mod_hash, ann_fn (mkVarOcc "module"), -- See mkIfaceAnnCache mi_usages iface0, sorted_deps, mi_hpc iface0) let no_change_at_all = Just iface_hash == mb_old_fingerprint final_iface = iface0 { mi_mod_hash = mod_hash, mi_iface_hash = iface_hash, mi_exp_hash = export_hash, mi_orphan_hash = orphan_hash, mi_flag_hash = flag_hash, mi_orphan = not ( all ifRuleAuto orph_rules -- See Note [Orphans and auto-generated rules] && null orph_insts && null orph_fis && isNoIfaceVectInfo (mi_vect_info iface0)), mi_finsts = not . null $ mi_fam_insts iface0, mi_decls = sorted_decls, mi_hash_fn = lookupOccEnv local_env } -- return (final_iface, no_change_at_all) where this_mod = mi_module iface0 semantic_mod = mi_semantic_module iface0 dflags = hsc_dflags hsc_env this_pkg = thisPackage dflags (non_orph_insts, orph_insts) = mkOrphMap ifInstOrph (mi_insts iface0) (non_orph_rules, orph_rules) = mkOrphMap ifRuleOrph (mi_rules iface0) (non_orph_fis, orph_fis) = mkOrphMap ifFamInstOrph (mi_fam_insts iface0) fix_fn = mi_fix_fn iface0 ann_fn = mkIfaceAnnCache (mi_anns iface0) getOrphanHashes :: HscEnv -> [Module] -> IO [Fingerprint] getOrphanHashes hsc_env mods = do eps <- hscEPS hsc_env let hpt = hsc_HPT hsc_env pit = eps_PIT eps dflags = hsc_dflags hsc_env get_orph_hash mod = case lookupIfaceByModule dflags hpt pit mod of Nothing -> pprPanic "moduleOrphanHash" (ppr mod) Just iface -> mi_orphan_hash iface -- return (map get_orph_hash mods) sortDependencies :: Dependencies -> Dependencies sortDependencies d = Deps { dep_mods = sortBy (compare `on` (moduleNameFS.fst)) (dep_mods d), dep_pkgs = sortBy (compare `on` fst) (dep_pkgs d), dep_orphs = sortBy stableModuleCmp (dep_orphs d), dep_finsts = sortBy stableModuleCmp (dep_finsts d) } -- | Creates cached lookup for the 'mi_anns' field of ModIface -- Hackily, we use "module" as the OccName for any module-level annotations mkIfaceAnnCache :: [IfaceAnnotation] -> OccName -> [AnnPayload] mkIfaceAnnCache anns = \n -> lookupOccEnv env n `orElse` [] where pair (IfaceAnnotation target value) = (case target of NamedTarget occn -> occn ModuleTarget _ -> mkVarOcc "module" , [value]) -- flipping (++), so the first argument is always short env = mkOccEnv_C (flip (++)) (map pair anns) {- ************************************************************************ * * The ABI of an IfaceDecl * * ************************************************************************ Note [The ABI of an IfaceDecl] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The ABI of a declaration consists of: (a) the full name of the identifier (inc. module and package, because these are used to construct the symbol name by which the identifier is known externally). (b) the declaration itself, as exposed to clients. That is, the definition of an Id is included in the fingerprint only if it is made available as an unfolding in the interface. (c) the fixity of the identifier (if it exists) (d) for Ids: rules (e) for classes: instances, fixity & rules for methods (f) for datatypes: instances, fixity & rules for constrs Items (c)-(f) are not stored in the IfaceDecl, but instead appear elsewhere in the interface file. But they are *fingerprinted* with the declaration itself. This is done by grouping (c)-(f) in IfaceDeclExtras, and fingerprinting that as part of the declaration. -} type IfaceDeclABI = (Module, IfaceDecl, IfaceDeclExtras) data IfaceDeclExtras = IfaceIdExtras IfaceIdExtras | IfaceDataExtras (Maybe Fixity) -- Fixity of the tycon itself (if it exists) [IfaceInstABI] -- Local class and family instances of this tycon -- See Note [Orphans] in InstEnv [AnnPayload] -- Annotations of the type itself [IfaceIdExtras] -- For each constructor: fixity, RULES and annotations | IfaceClassExtras (Maybe Fixity) -- Fixity of the class itself (if it exists) [IfaceInstABI] -- Local instances of this class *or* -- of its associated data types -- See Note [Orphans] in InstEnv [AnnPayload] -- Annotations of the type itself [IfaceIdExtras] -- For each class method: fixity, RULES and annotations | IfaceSynonymExtras (Maybe Fixity) [AnnPayload] | IfaceFamilyExtras (Maybe Fixity) [IfaceInstABI] [AnnPayload] | IfaceOtherDeclExtras data IfaceIdExtras = IdExtras (Maybe Fixity) -- Fixity of the Id (if it exists) [IfaceRule] -- Rules for the Id [AnnPayload] -- Annotations for the Id -- When hashing a class or family instance, we hash only the -- DFunId or CoAxiom, because that depends on all the -- information about the instance. -- type IfaceInstABI = IfExtName -- Name of DFunId or CoAxiom that is evidence for the instance abiDecl :: IfaceDeclABI -> IfaceDecl abiDecl (_, decl, _) = decl cmp_abiNames :: IfaceDeclABI -> IfaceDeclABI -> Ordering cmp_abiNames abi1 abi2 = ifName (abiDecl abi1) `compare` ifName (abiDecl abi2) freeNamesDeclABI :: IfaceDeclABI -> NameSet freeNamesDeclABI (_mod, decl, extras) = freeNamesIfDecl decl `unionNameSet` freeNamesDeclExtras extras freeNamesDeclExtras :: IfaceDeclExtras -> NameSet freeNamesDeclExtras (IfaceIdExtras id_extras) = freeNamesIdExtras id_extras freeNamesDeclExtras (IfaceDataExtras _ insts _ subs) = unionNameSets (mkNameSet insts : map freeNamesIdExtras subs) freeNamesDeclExtras (IfaceClassExtras _ insts _ subs) = unionNameSets (mkNameSet insts : map freeNamesIdExtras subs) freeNamesDeclExtras (IfaceSynonymExtras _ _) = emptyNameSet freeNamesDeclExtras (IfaceFamilyExtras _ insts _) = mkNameSet insts freeNamesDeclExtras IfaceOtherDeclExtras = emptyNameSet freeNamesIdExtras :: IfaceIdExtras -> NameSet freeNamesIdExtras (IdExtras _ rules _) = unionNameSets (map freeNamesIfRule rules) instance Outputable IfaceDeclExtras where ppr IfaceOtherDeclExtras = Outputable.empty ppr (IfaceIdExtras extras) = ppr_id_extras extras ppr (IfaceSynonymExtras fix anns) = vcat [ppr fix, ppr anns] ppr (IfaceFamilyExtras fix finsts anns) = vcat [ppr fix, ppr finsts, ppr anns] ppr (IfaceDataExtras fix insts anns stuff) = vcat [ppr fix, ppr_insts insts, ppr anns, ppr_id_extras_s stuff] ppr (IfaceClassExtras fix insts anns stuff) = vcat [ppr fix, ppr_insts insts, ppr anns, ppr_id_extras_s stuff] ppr_insts :: [IfaceInstABI] -> SDoc ppr_insts _ = text "<insts>" ppr_id_extras_s :: [IfaceIdExtras] -> SDoc ppr_id_extras_s stuff = vcat (map ppr_id_extras stuff) ppr_id_extras :: IfaceIdExtras -> SDoc ppr_id_extras (IdExtras fix rules anns) = ppr fix $$ vcat (map ppr rules) $$ vcat (map ppr anns) -- This instance is used only to compute fingerprints instance Binary IfaceDeclExtras where get _bh = panic "no get for IfaceDeclExtras" put_ bh (IfaceIdExtras extras) = do putByte bh 1; put_ bh extras put_ bh (IfaceDataExtras fix insts anns cons) = do putByte bh 2; put_ bh fix; put_ bh insts; put_ bh anns; put_ bh cons put_ bh (IfaceClassExtras fix insts anns methods) = do putByte bh 3; put_ bh fix; put_ bh insts; put_ bh anns; put_ bh methods put_ bh (IfaceSynonymExtras fix anns) = do putByte bh 4; put_ bh fix; put_ bh anns put_ bh (IfaceFamilyExtras fix finsts anns) = do putByte bh 5; put_ bh fix; put_ bh finsts; put_ bh anns put_ bh IfaceOtherDeclExtras = putByte bh 6 instance Binary IfaceIdExtras where get _bh = panic "no get for IfaceIdExtras" put_ bh (IdExtras fix rules anns)= do { put_ bh fix; put_ bh rules; put_ bh anns } declExtras :: (OccName -> Maybe Fixity) -> (OccName -> [AnnPayload]) -> OccEnv [IfaceRule] -> OccEnv [IfaceClsInst] -> OccEnv [IfaceFamInst] -> IfaceDecl -> IfaceDeclExtras declExtras fix_fn ann_fn rule_env inst_env fi_env decl = case decl of IfaceId{} -> IfaceIdExtras (id_extras n) IfaceData{ifCons=cons} -> IfaceDataExtras (fix_fn n) (map ifFamInstAxiom (lookupOccEnvL fi_env n) ++ map ifDFun (lookupOccEnvL inst_env n)) (ann_fn n) (map (id_extras . ifConOcc) (visibleIfConDecls cons)) IfaceClass{ifSigs=sigs, ifATs=ats} -> IfaceClassExtras (fix_fn n) (map ifDFun $ (concatMap at_extras ats) ++ lookupOccEnvL inst_env n) -- Include instances of the associated types -- as well as instances of the class (Trac #5147) (ann_fn n) [id_extras op | IfaceClassOp op _ _ <- sigs] IfaceSynonym{} -> IfaceSynonymExtras (fix_fn n) (ann_fn n) IfaceFamily{} -> IfaceFamilyExtras (fix_fn n) (map ifFamInstAxiom (lookupOccEnvL fi_env n)) (ann_fn n) _other -> IfaceOtherDeclExtras where n = ifName decl id_extras occ = IdExtras (fix_fn occ) (lookupOccEnvL rule_env occ) (ann_fn occ) at_extras (IfaceAT decl _) = lookupOccEnvL inst_env (ifName decl) lookupOccEnvL :: OccEnv [v] -> OccName -> [v] lookupOccEnvL env k = lookupOccEnv env k `orElse` [] -- used when we want to fingerprint a structure without depending on the -- fingerprints of external Names that it refers to. putNameLiterally :: BinHandle -> Name -> IO () putNameLiterally bh name = ASSERT( isExternalName name ) do put_ bh $! nameModule name put_ bh $! nameOccName name {- -- for testing: use the md5sum command to generate fingerprints and -- compare the results against our built-in version. fp' <- oldMD5 dflags bh if fp /= fp' then pprPanic "computeFingerprint" (ppr fp <+> ppr fp') else return fp oldMD5 dflags bh = do tmp <- newTempName dflags "bin" writeBinMem bh tmp tmp2 <- newTempName dflags "md5" let cmd = "md5sum " ++ tmp ++ " >" ++ tmp2 r <- system cmd case r of ExitFailure _ -> throwGhcExceptionIO (PhaseFailed cmd r) ExitSuccess -> do hash_str <- readFile tmp2 return $! readHexFingerprint hash_str -} ---------------------- -- mkOrphMap partitions instance decls or rules into -- (a) an OccEnv for ones that are not orphans, -- mapping the local OccName to a list of its decls -- (b) a list of orphan decls mkOrphMap :: (decl -> IsOrphan) -- Extract orphan status from decl -> [decl] -- Sorted into canonical order -> (OccEnv [decl], -- Non-orphan decls associated with their key; -- each sublist in canonical order [decl]) -- Orphan decls; in canonical order mkOrphMap get_key decls = foldl go (emptyOccEnv, []) decls where go (non_orphs, orphs) d | NotOrphan occ <- get_key d = (extendOccEnv_Acc (:) singleton non_orphs occ d, orphs) | otherwise = (non_orphs, d:orphs) {- ************************************************************************ * * Keeping track of what we've slurped, and fingerprints * * ************************************************************************ -} mkIfaceAnnotation :: Annotation -> IfaceAnnotation mkIfaceAnnotation (Annotation { ann_target = target, ann_value = payload }) = IfaceAnnotation { ifAnnotatedTarget = fmap nameOccName target, ifAnnotatedValue = payload } mkIfaceExports :: [AvailInfo] -> [IfaceExport] -- Sort to make canonical mkIfaceExports exports = sortBy stableAvailCmp (map sort_subs exports) where sort_subs :: AvailInfo -> AvailInfo sort_subs (Avail n) = Avail n sort_subs (AvailTC n [] fs) = AvailTC n [] (sort_flds fs) sort_subs (AvailTC n (m:ms) fs) | n==m = AvailTC n (m:sortBy stableNameCmp ms) (sort_flds fs) | otherwise = AvailTC n (sortBy stableNameCmp (m:ms)) (sort_flds fs) -- Maintain the AvailTC Invariant sort_flds = sortBy (stableNameCmp `on` flSelector) {- Note [Orignal module] ~~~~~~~~~~~~~~~~~~~~~ Consider this: module X where { data family T } module Y( T(..) ) where { import X; data instance T Int = MkT Int } The exported Avail from Y will look like X.T{X.T, Y.MkT} That is, in Y, - only MkT is brought into scope by the data instance; - but the parent (used for grouping and naming in T(..) exports) is X.T - and in this case we export X.T too In the result of MkIfaceExports, the names are grouped by defining module, so we may need to split up a single Avail into multiple ones. Note [Internal used_names] ~~~~~~~~~~~~~~~~~~~~~~~~~~ Most of the used_names are External Names, but we can have Internal Names too: see Note [Binders in Template Haskell] in Convert, and Trac #5362 for an example. Such Names are always - Such Names are always for locally-defined things, for which we don't gather usage info, so we can just ignore them in ent_map - They are always System Names, hence the assert, just as a double check. ************************************************************************ * * Load the old interface file for this module (unless we have it already), and check whether it is up to date * * ************************************************************************ -} data RecompileRequired = UpToDate -- ^ everything is up to date, recompilation is not required | MustCompile -- ^ The .hs file has been touched, or the .o/.hi file does not exist | RecompBecause String -- ^ The .o/.hi files are up to date, but something else has changed -- to force recompilation; the String says what (one-line summary) deriving Eq recompileRequired :: RecompileRequired -> Bool recompileRequired UpToDate = False recompileRequired _ = True -- | Top level function to check if the version of an old interface file -- is equivalent to the current source file the user asked us to compile. -- If the same, we can avoid recompilation. We return a tuple where the -- first element is a bool saying if we should recompile the object file -- and the second is maybe the interface file, where Nothng means to -- rebuild the interface file not use the exisitng one. checkOldIface :: HscEnv -> ModSummary -> SourceModified -> Maybe ModIface -- Old interface from compilation manager, if any -> IO (RecompileRequired, Maybe ModIface) checkOldIface hsc_env mod_summary source_modified maybe_iface = do let dflags = hsc_dflags hsc_env showPass dflags $ "Checking old interface for " ++ (showPpr dflags $ ms_mod mod_summary) initIfaceCheck (text "checkOldIface") hsc_env $ check_old_iface hsc_env mod_summary source_modified maybe_iface check_old_iface :: HscEnv -> ModSummary -> SourceModified -> Maybe ModIface -> IfG (RecompileRequired, Maybe ModIface) check_old_iface hsc_env mod_summary src_modified maybe_iface = let dflags = hsc_dflags hsc_env getIface = case maybe_iface of Just _ -> do traceIf (text "We already have the old interface for" <+> ppr (ms_mod mod_summary)) return maybe_iface Nothing -> loadIface loadIface = do let iface_path = msHiFilePath mod_summary read_result <- readIface (ms_installed_mod mod_summary) iface_path case read_result of Failed err -> do traceIf (text "FYI: cannot read old interface file:" $$ nest 4 err) return Nothing Succeeded iface -> do traceIf (text "Read the interface file" <+> text iface_path) return $ Just iface src_changed | gopt Opt_ForceRecomp (hsc_dflags hsc_env) = True | SourceModified <- src_modified = True | otherwise = False in do when src_changed $ traceHiDiffs (nest 4 $ text "Source file changed or recompilation check turned off") case src_changed of -- If the source has changed and we're in interactive mode, -- avoid reading an interface; just return the one we might -- have been supplied with. True | not (isObjectTarget $ hscTarget dflags) -> return (MustCompile, maybe_iface) -- Try and read the old interface for the current module -- from the .hi file left from the last time we compiled it True -> do maybe_iface' <- getIface return (MustCompile, maybe_iface') False -> do maybe_iface' <- getIface case maybe_iface' of -- We can't retrieve the iface Nothing -> return (MustCompile, Nothing) -- We have got the old iface; check its versions -- even in the SourceUnmodifiedAndStable case we -- should check versions because some packages -- might have changed or gone away. Just iface -> checkVersions hsc_env mod_summary iface -- | Check if a module is still the same 'version'. -- -- This function is called in the recompilation checker after we have -- determined that the module M being checked hasn't had any changes -- to its source file since we last compiled M. So at this point in general -- two things may have changed that mean we should recompile M: -- * The interface export by a dependency of M has changed. -- * The compiler flags specified this time for M have changed -- in a manner that is significant for recompilaiton. -- We return not just if we should recompile the object file but also -- if we should rebuild the interface file. checkVersions :: HscEnv -> ModSummary -> ModIface -- Old interface -> IfG (RecompileRequired, Maybe ModIface) checkVersions hsc_env mod_summary iface = do { traceHiDiffs (text "Considering whether compilation is required for" <+> ppr (mi_module iface) <> colon) ; recomp <- checkFlagHash hsc_env iface ; if recompileRequired recomp then return (recomp, Nothing) else do { ; recomp <- checkHsig mod_summary iface ; if recompileRequired recomp then return (recomp, Nothing) else do { ; recomp <- checkDependencies hsc_env mod_summary iface ; if recompileRequired recomp then return (recomp, Just iface) else do { -- Source code unchanged and no errors yet... carry on -- -- First put the dependent-module info, read from the old -- interface, into the envt, so that when we look for -- interfaces we look for the right one (.hi or .hi-boot) -- -- It's just temporary because either the usage check will succeed -- (in which case we are done with this module) or it'll fail (in which -- case we'll compile the module from scratch anyhow). -- -- We do this regardless of compilation mode, although in --make mode -- all the dependent modules should be in the HPT already, so it's -- quite redundant ; updateEps_ $ \eps -> eps { eps_is_boot = udfmToUfm mod_deps } ; recomp <- checkList [checkModUsage this_pkg u | u <- mi_usages iface] ; return (recomp, Just iface) }}}} where this_pkg = thisPackage (hsc_dflags hsc_env) -- This is a bit of a hack really mod_deps :: DModuleNameEnv (ModuleName, IsBootInterface) mod_deps = mkModDeps (dep_mods (mi_deps iface)) -- | Check if an hsig file needs recompilation because its -- implementing module has changed. checkHsig :: ModSummary -> ModIface -> IfG RecompileRequired checkHsig mod_summary iface = do dflags <- getDynFlags let outer_mod = ms_mod mod_summary inner_mod = canonicalizeHomeModule dflags (moduleName outer_mod) MASSERT( moduleUnitId outer_mod == thisPackage dflags ) case inner_mod == mi_semantic_module iface of True -> up_to_date (text "implementing module unchanged") False -> return (RecompBecause "implementing module changed") -- | Check the flags haven't changed checkFlagHash :: HscEnv -> ModIface -> IfG RecompileRequired checkFlagHash hsc_env iface = do let old_hash = mi_flag_hash iface new_hash <- liftIO $ fingerprintDynFlags (hsc_dflags hsc_env) (mi_module iface) putNameLiterally case old_hash == new_hash of True -> up_to_date (text "Module flags unchanged") False -> out_of_date_hash "flags changed" (text " Module flags have changed") old_hash new_hash -- If the direct imports of this module are resolved to targets that -- are not among the dependencies of the previous interface file, -- then we definitely need to recompile. This catches cases like -- - an exposed package has been upgraded -- - we are compiling with different package flags -- - a home module that was shadowing a package module has been removed -- - a new home module has been added that shadows a package module -- See bug #1372. -- -- Returns (RecompBecause <textual reason>) if recompilation is required. checkDependencies :: HscEnv -> ModSummary -> ModIface -> IfG RecompileRequired checkDependencies hsc_env summary iface = checkList (map dep_missing (ms_imps summary ++ ms_srcimps summary)) where prev_dep_mods = dep_mods (mi_deps iface) prev_dep_pkgs = dep_pkgs (mi_deps iface) this_pkg = thisPackage (hsc_dflags hsc_env) dep_missing (mb_pkg, L _ mod) = do find_res <- liftIO $ findImportedModule hsc_env mod (mb_pkg) let reason = moduleNameString mod ++ " changed" case find_res of Found _ mod | pkg == this_pkg -> if moduleName mod `notElem` map fst prev_dep_mods then do traceHiDiffs $ text "imported module " <> quotes (ppr mod) <> text " not among previous dependencies" return (RecompBecause reason) else return UpToDate | otherwise -> if toInstalledUnitId pkg `notElem` (map fst prev_dep_pkgs) then do traceHiDiffs $ text "imported module " <> quotes (ppr mod) <> text " is from package " <> quotes (ppr pkg) <> text ", which is not among previous dependencies" return (RecompBecause reason) else return UpToDate where pkg = moduleUnitId mod _otherwise -> return (RecompBecause reason) needInterface :: Module -> (ModIface -> IfG RecompileRequired) -> IfG RecompileRequired needInterface mod continue = do -- Load the imported interface if possible let doc_str = sep [text "need version info for", ppr mod] traceHiDiffs (text "Checking usages for module" <+> ppr mod) mb_iface <- loadInterface doc_str mod ImportBySystem -- Load the interface, but don't complain on failure; -- Instead, get an Either back which we can test case mb_iface of Failed _ -> do traceHiDiffs (sep [text "Couldn't load interface for module", ppr mod]) return MustCompile -- Couldn't find or parse a module mentioned in the -- old interface file. Don't complain: it might -- just be that the current module doesn't need that -- import and it's been deleted Succeeded iface -> continue iface -- | Given the usage information extracted from the old -- M.hi file for the module being compiled, figure out -- whether M needs to be recompiled. checkModUsage :: UnitId -> Usage -> IfG RecompileRequired checkModUsage _this_pkg UsagePackageModule{ usg_mod = mod, usg_mod_hash = old_mod_hash } = needInterface mod $ \iface -> do let reason = moduleNameString (moduleName mod) ++ " changed" checkModuleFingerprint reason old_mod_hash (mi_mod_hash iface) -- We only track the ABI hash of package modules, rather than -- individual entity usages, so if the ABI hash changes we must -- recompile. This is safe but may entail more recompilation when -- a dependent package has changed. checkModUsage _ UsageMergedRequirement{ usg_mod = mod, usg_mod_hash = old_mod_hash } = needInterface mod $ \iface -> do let reason = moduleNameString (moduleName mod) ++ " changed (raw)" checkModuleFingerprint reason old_mod_hash (mi_mod_hash iface) checkModUsage this_pkg UsageHomeModule{ usg_mod_name = mod_name, usg_mod_hash = old_mod_hash, usg_exports = maybe_old_export_hash, usg_entities = old_decl_hash } = do let mod = mkModule this_pkg mod_name needInterface mod $ \iface -> do let new_mod_hash = mi_mod_hash iface new_decl_hash = mi_hash_fn iface new_export_hash = mi_exp_hash iface reason = moduleNameString mod_name ++ " changed" -- CHECK MODULE recompile <- checkModuleFingerprint reason old_mod_hash new_mod_hash if not (recompileRequired recompile) then return UpToDate else do -- CHECK EXPORT LIST checkMaybeHash reason maybe_old_export_hash new_export_hash (text " Export list changed") $ do -- CHECK ITEMS ONE BY ONE recompile <- checkList [ checkEntityUsage reason new_decl_hash u | u <- old_decl_hash] if recompileRequired recompile then return recompile -- This one failed, so just bail out now else up_to_date (text " Great! The bits I use are up to date") checkModUsage _this_pkg UsageFile{ usg_file_path = file, usg_file_hash = old_hash } = liftIO $ handleIO handle $ do new_hash <- getFileHash file if (old_hash /= new_hash) then return recomp else return UpToDate where recomp = RecompBecause (file ++ " changed") handle = #ifdef DEBUG \e -> pprTrace "UsageFile" (text (show e)) $ return recomp #else \_ -> return recomp -- if we can't find the file, just recompile, don't fail #endif ------------------------ checkModuleFingerprint :: String -> Fingerprint -> Fingerprint -> IfG RecompileRequired checkModuleFingerprint reason old_mod_hash new_mod_hash | new_mod_hash == old_mod_hash = up_to_date (text "Module fingerprint unchanged") | otherwise = out_of_date_hash reason (text " Module fingerprint has changed") old_mod_hash new_mod_hash ------------------------ checkMaybeHash :: String -> Maybe Fingerprint -> Fingerprint -> SDoc -> IfG RecompileRequired -> IfG RecompileRequired checkMaybeHash reason maybe_old_hash new_hash doc continue | Just hash <- maybe_old_hash, hash /= new_hash = out_of_date_hash reason doc hash new_hash | otherwise = continue ------------------------ checkEntityUsage :: String -> (OccName -> Maybe (OccName, Fingerprint)) -> (OccName, Fingerprint) -> IfG RecompileRequired checkEntityUsage reason new_hash (name,old_hash) = case new_hash name of Nothing -> -- We used it before, but it ain't there now out_of_date reason (sep [text "No longer exported:", ppr name]) Just (_, new_hash) -- It's there, but is it up to date? | new_hash == old_hash -> do traceHiDiffs (text " Up to date" <+> ppr name <+> parens (ppr new_hash)) return UpToDate | otherwise -> out_of_date_hash reason (text " Out of date:" <+> ppr name) old_hash new_hash up_to_date :: SDoc -> IfG RecompileRequired up_to_date msg = traceHiDiffs msg >> return UpToDate out_of_date :: String -> SDoc -> IfG RecompileRequired out_of_date reason msg = traceHiDiffs msg >> return (RecompBecause reason) out_of_date_hash :: String -> SDoc -> Fingerprint -> Fingerprint -> IfG RecompileRequired out_of_date_hash reason msg old_hash new_hash = out_of_date reason (hsep [msg, ppr old_hash, text "->", ppr new_hash]) ---------------------- checkList :: [IfG RecompileRequired] -> IfG RecompileRequired -- This helper is used in two places checkList [] = return UpToDate checkList (check:checks) = do recompile <- check if recompileRequired recompile then return recompile else checkList checks {- ************************************************************************ * * Converting things to their Iface equivalents * * ************************************************************************ -} tyThingToIfaceDecl :: TyThing -> IfaceDecl tyThingToIfaceDecl (AnId id) = idToIfaceDecl id tyThingToIfaceDecl (ATyCon tycon) = snd (tyConToIfaceDecl emptyTidyEnv tycon) tyThingToIfaceDecl (ACoAxiom ax) = coAxiomToIfaceDecl ax tyThingToIfaceDecl (AConLike cl) = case cl of RealDataCon dc -> dataConToIfaceDecl dc -- for ppr purposes only PatSynCon ps -> patSynToIfaceDecl ps -------------------------- idToIfaceDecl :: Id -> IfaceDecl -- The Id is already tidied, so that locally-bound names -- (lambdas, for-alls) already have non-clashing OccNames -- We can't tidy it here, locally, because it may have -- free variables in its type or IdInfo idToIfaceDecl id = IfaceId { ifName = getOccName id, ifType = toIfaceType (idType id), ifIdDetails = toIfaceIdDetails (idDetails id), ifIdInfo = toIfaceIdInfo (idInfo id) } -------------------------- dataConToIfaceDecl :: DataCon -> IfaceDecl dataConToIfaceDecl dataCon = IfaceId { ifName = getOccName dataCon, ifType = toIfaceType (dataConUserType dataCon), ifIdDetails = IfVanillaId, ifIdInfo = NoInfo } -------------------------- patSynToIfaceDecl :: PatSyn -> IfaceDecl patSynToIfaceDecl ps = IfacePatSyn { ifName = getOccName . getName $ ps , ifPatMatcher = to_if_pr (patSynMatcher ps) , ifPatBuilder = fmap to_if_pr (patSynBuilder ps) , ifPatIsInfix = patSynIsInfix ps , ifPatUnivBndrs = map toIfaceForAllBndr univ_bndrs' , ifPatExBndrs = map toIfaceForAllBndr ex_bndrs' , ifPatProvCtxt = tidyToIfaceContext env2 prov_theta , ifPatReqCtxt = tidyToIfaceContext env2 req_theta , ifPatArgs = map (tidyToIfaceType env2) args , ifPatTy = tidyToIfaceType env2 rhs_ty , ifFieldLabels = (patSynFieldLabels ps) } where (_univ_tvs, req_theta, _ex_tvs, prov_theta, args, rhs_ty) = patSynSig ps univ_bndrs = patSynUnivTyVarBinders ps ex_bndrs = patSynExTyVarBinders ps (env1, univ_bndrs') = tidyTyVarBinders emptyTidyEnv univ_bndrs (env2, ex_bndrs') = tidyTyVarBinders env1 ex_bndrs to_if_pr (id, needs_dummy) = (idName id, needs_dummy) -------------------------- coAxiomToIfaceDecl :: CoAxiom br -> IfaceDecl -- We *do* tidy Axioms, because they are not (and cannot -- conveniently be) built in tidy form coAxiomToIfaceDecl ax@(CoAxiom { co_ax_tc = tycon, co_ax_branches = branches , co_ax_role = role }) = IfaceAxiom { ifName = name , ifTyCon = toIfaceTyCon tycon , ifRole = role , ifAxBranches = map (coAxBranchToIfaceBranch tycon (map coAxBranchLHS branch_list)) branch_list } where branch_list = fromBranches branches name = getOccName ax -- 2nd parameter is the list of branch LHSs, for conversion from incompatible branches -- to incompatible indices -- See Note [Storing compatibility] in CoAxiom coAxBranchToIfaceBranch :: TyCon -> [[Type]] -> CoAxBranch -> IfaceAxBranch coAxBranchToIfaceBranch tc lhs_s branch@(CoAxBranch { cab_incomps = incomps }) = (coAxBranchToIfaceBranch' tc branch) { ifaxbIncomps = iface_incomps } where iface_incomps = map (expectJust "iface_incomps" . (flip findIndex lhs_s . eqTypes) . coAxBranchLHS) incomps -- use this one for standalone branches without incompatibles coAxBranchToIfaceBranch' :: TyCon -> CoAxBranch -> IfaceAxBranch coAxBranchToIfaceBranch' tc (CoAxBranch { cab_tvs = tvs, cab_cvs = cvs , cab_lhs = lhs , cab_roles = roles, cab_rhs = rhs }) = IfaceAxBranch { ifaxbTyVars = toIfaceTvBndrs tidy_tvs , ifaxbCoVars = map toIfaceIdBndr cvs , ifaxbLHS = tidyToIfaceTcArgs env1 tc lhs , ifaxbRoles = roles , ifaxbRHS = tidyToIfaceType env1 rhs , ifaxbIncomps = [] } where (env1, tidy_tvs) = tidyTyCoVarBndrs emptyTidyEnv tvs -- Don't re-bind in-scope tyvars -- See Note [CoAxBranch type variables] in CoAxiom ----------------- tyConToIfaceDecl :: TidyEnv -> TyCon -> (TidyEnv, IfaceDecl) -- We *do* tidy TyCons, because they are not (and cannot -- conveniently be) built in tidy form -- The returned TidyEnv is the one after tidying the tyConTyVars tyConToIfaceDecl env tycon | Just clas <- tyConClass_maybe tycon = classToIfaceDecl env clas | Just syn_rhs <- synTyConRhs_maybe tycon = ( tc_env1 , IfaceSynonym { ifName = getOccName tycon, ifRoles = tyConRoles tycon, ifSynRhs = if_syn_type syn_rhs, ifBinders = if_binders, ifResKind = if_res_kind }) | Just fam_flav <- famTyConFlav_maybe tycon = ( tc_env1 , IfaceFamily { ifName = getOccName tycon, ifResVar = if_res_var, ifFamFlav = to_if_fam_flav fam_flav, ifBinders = if_binders, ifResKind = if_res_kind, ifFamInj = familyTyConInjectivityInfo tycon }) | isAlgTyCon tycon = ( tc_env1 , IfaceData { ifName = getOccName tycon, ifBinders = if_binders, ifResKind = if_res_kind, ifCType = tyConCType tycon, ifRoles = tyConRoles tycon, ifCtxt = tidyToIfaceContext tc_env1 (tyConStupidTheta tycon), ifCons = ifaceConDecls (algTyConRhs tycon) (algTcFields tycon), ifGadtSyntax = isGadtSyntaxTyCon tycon, ifParent = parent }) | otherwise -- FunTyCon, PrimTyCon, promoted TyCon/DataCon -- We only convert these TyCons to IfaceTyCons when we are -- just about to pretty-print them, not because we are going -- to put them into interface files = ( env , IfaceData { ifName = getOccName tycon, ifBinders = if_binders, ifResKind = if_res_kind, ifCType = Nothing, ifRoles = tyConRoles tycon, ifCtxt = [], ifCons = IfDataTyCon [] False [], ifGadtSyntax = False, ifParent = IfNoParent }) where -- NOTE: Not all TyCons have `tyConTyVars` field. Forcing this when `tycon` -- is one of these TyCons (FunTyCon, PrimTyCon, PromotedDataCon) will cause -- an error. (tc_env1, tc_binders) = tidyTyConBinders env (tyConBinders tycon) tc_tyvars = binderVars tc_binders if_binders = toIfaceTyVarBinders tc_binders if_res_kind = tidyToIfaceType tc_env1 (tyConResKind tycon) if_syn_type ty = tidyToIfaceType tc_env1 ty if_res_var = getOccFS `fmap` tyConFamilyResVar_maybe tycon parent = case tyConFamInstSig_maybe tycon of Just (tc, ty, ax) -> IfDataInstance (coAxiomName ax) (toIfaceTyCon tc) (tidyToIfaceTcArgs tc_env1 tc ty) Nothing -> IfNoParent to_if_fam_flav OpenSynFamilyTyCon = IfaceOpenSynFamilyTyCon to_if_fam_flav (ClosedSynFamilyTyCon (Just ax)) = IfaceClosedSynFamilyTyCon (Just (axn, ibr)) where defs = fromBranches $ coAxiomBranches ax ibr = map (coAxBranchToIfaceBranch' tycon) defs axn = coAxiomName ax to_if_fam_flav (ClosedSynFamilyTyCon Nothing) = IfaceClosedSynFamilyTyCon Nothing to_if_fam_flav AbstractClosedSynFamilyTyCon = IfaceAbstractClosedSynFamilyTyCon to_if_fam_flav (DataFamilyTyCon {}) = IfaceDataFamilyTyCon to_if_fam_flav (BuiltInSynFamTyCon {}) = IfaceBuiltInSynFamTyCon ifaceConDecls (NewTyCon { data_con = con }) flds = IfNewTyCon (ifaceConDecl con) (ifaceOverloaded flds) (ifaceFields flds) ifaceConDecls (DataTyCon { data_cons = cons }) flds = IfDataTyCon (map ifaceConDecl cons) (ifaceOverloaded flds) (ifaceFields flds) ifaceConDecls (TupleTyCon { data_con = con }) _ = IfDataTyCon [ifaceConDecl con] False [] ifaceConDecls (SumTyCon { data_cons = cons }) flds = IfDataTyCon (map ifaceConDecl cons) (ifaceOverloaded flds) (ifaceFields flds) ifaceConDecls (AbstractTyCon distinct) _ = IfAbstractTyCon distinct -- The AbstractTyCon case happens when a TyCon has been trimmed -- during tidying. -- Furthermore, tyThingToIfaceDecl is also used in TcRnDriver -- for GHCi, when browsing a module, in which case the -- AbstractTyCon and TupleTyCon cases are perfectly sensible. -- (Tuple declarations are not serialised into interface files.) ifaceConDecl data_con = IfCon { ifConOcc = getOccName (dataConName data_con), ifConInfix = dataConIsInfix data_con, ifConWrapper = isJust (dataConWrapId_maybe data_con), ifConExTvs = map toIfaceForAllBndr ex_bndrs', ifConEqSpec = map (to_eq_spec . eqSpecPair) eq_spec, ifConCtxt = tidyToIfaceContext con_env2 theta, ifConArgTys = map (tidyToIfaceType con_env2) arg_tys, ifConFields = map (nameOccName . flSelector) (dataConFieldLabels data_con), ifConStricts = map (toIfaceBang con_env2) (dataConImplBangs data_con), ifConSrcStricts = map toIfaceSrcBang (dataConSrcBangs data_con)} where (univ_tvs, _ex_tvs, eq_spec, theta, arg_tys, _) = dataConFullSig data_con ex_bndrs = dataConExTyVarBinders data_con -- Tidy the univ_tvs of the data constructor to be identical -- to the tyConTyVars of the type constructor. This means -- (a) we don't need to redundantly put them into the interface file -- (b) when pretty-printing an Iface data declaration in H98-style syntax, -- we know that the type variables will line up -- The latter (b) is important because we pretty-print type constructors -- by converting to IfaceSyn and pretty-printing that con_env1 = (fst tc_env1, mkVarEnv (zipEqual "ifaceConDecl" univ_tvs tc_tyvars)) -- A bit grimy, perhaps, but it's simple! (con_env2, ex_bndrs') = tidyTyVarBinders con_env1 ex_bndrs to_eq_spec (tv,ty) = (tidyTyVar con_env2 tv, tidyToIfaceType con_env2 ty) ifaceOverloaded flds = case dFsEnvElts flds of fl:_ -> flIsOverloaded fl [] -> False ifaceFields flds = map flLabel $ dFsEnvElts flds toIfaceBang :: TidyEnv -> HsImplBang -> IfaceBang toIfaceBang _ HsLazy = IfNoBang toIfaceBang _ (HsUnpack Nothing) = IfUnpack toIfaceBang env (HsUnpack (Just co)) = IfUnpackCo (toIfaceCoercion (tidyCo env co)) toIfaceBang _ HsStrict = IfStrict toIfaceSrcBang :: HsSrcBang -> IfaceSrcBang toIfaceSrcBang (HsSrcBang _ unpk bang) = IfSrcBang unpk bang classToIfaceDecl :: TidyEnv -> Class -> (TidyEnv, IfaceDecl) classToIfaceDecl env clas = ( env1 , IfaceClass { ifCtxt = tidyToIfaceContext env1 sc_theta, ifName = getOccName tycon, ifRoles = tyConRoles (classTyCon clas), ifBinders = toIfaceTyVarBinders tc_binders, ifFDs = map toIfaceFD clas_fds, ifATs = map toIfaceAT clas_ats, ifSigs = map toIfaceClassOp op_stuff, ifMinDef = fmap getOccFS (classMinimalDef clas) }) where (_, clas_fds, sc_theta, _, clas_ats, op_stuff) = classExtraBigSig clas tycon = classTyCon clas (env1, tc_binders) = tidyTyConBinders env (tyConBinders tycon) toIfaceAT :: ClassATItem -> IfaceAT toIfaceAT (ATI tc def) = IfaceAT if_decl (fmap (tidyToIfaceType env2 . fst) def) where (env2, if_decl) = tyConToIfaceDecl env1 tc toIfaceClassOp (sel_id, def_meth) = ASSERT( sel_tyvars == binderVars tc_binders ) IfaceClassOp (getOccName sel_id) (tidyToIfaceType env1 op_ty) (fmap toDmSpec def_meth) where -- Be careful when splitting the type, because of things -- like class Foo a where -- op :: (?x :: String) => a -> a -- and class Baz a where -- op :: (Ord a) => a -> a (sel_tyvars, rho_ty) = splitForAllTys (idType sel_id) op_ty = funResultTy rho_ty toDmSpec :: (Name, DefMethSpec Type) -> DefMethSpec IfaceType toDmSpec (_, VanillaDM) = VanillaDM toDmSpec (_, GenericDM dm_ty) = GenericDM (tidyToIfaceType env1 dm_ty) toIfaceFD (tvs1, tvs2) = (map (tidyTyVar env1) tvs1 ,map (tidyTyVar env1) tvs2) -------------------------- tidyToIfaceType :: TidyEnv -> Type -> IfaceType tidyToIfaceType env ty = toIfaceType (tidyType env ty) tidyToIfaceTcArgs :: TidyEnv -> TyCon -> [Type] -> IfaceTcArgs tidyToIfaceTcArgs env tc tys = toIfaceTcArgs tc (tidyTypes env tys) tidyToIfaceContext :: TidyEnv -> ThetaType -> IfaceContext tidyToIfaceContext env theta = map (tidyToIfaceType env) theta toIfaceTyVarBinder :: TyVarBndr TyVar vis -> TyVarBndr IfaceTvBndr vis toIfaceTyVarBinder (TvBndr tv vis) = TvBndr (toIfaceTvBndr tv) vis toIfaceTyVarBinders :: [TyVarBndr TyVar vis] -> [TyVarBndr IfaceTvBndr vis] toIfaceTyVarBinders = map toIfaceTyVarBinder tidyTyConBinder :: TidyEnv -> TyConBinder -> (TidyEnv, TyConBinder) -- If the type variable "binder" is in scope, don't re-bind it -- In a class decl, for example, the ATD binders mention -- (amd must mention) the class tyvars tidyTyConBinder env@(_, subst) tvb@(TvBndr tv vis) = case lookupVarEnv subst tv of Just tv' -> (env, TvBndr tv' vis) Nothing -> tidyTyVarBinder env tvb tidyTyConBinders :: TidyEnv -> [TyConBinder] -> (TidyEnv, [TyConBinder]) tidyTyConBinders = mapAccumL tidyTyConBinder tidyTyVar :: TidyEnv -> TyVar -> FastString tidyTyVar (_, subst) tv = toIfaceTyVar (lookupVarEnv subst tv `orElse` tv) -------------------------- instanceToIfaceInst :: ClsInst -> IfaceClsInst instanceToIfaceInst (ClsInst { is_dfun = dfun_id, is_flag = oflag , is_cls_nm = cls_name, is_cls = cls , is_tcs = mb_tcs , is_orphan = orph }) = ASSERT( cls_name == className cls ) IfaceClsInst { ifDFun = dfun_name, ifOFlag = oflag, ifInstCls = cls_name, ifInstTys = map do_rough mb_tcs, ifInstOrph = orph } where do_rough Nothing = Nothing do_rough (Just n) = Just (toIfaceTyCon_name n) dfun_name = idName dfun_id -------------------------- famInstToIfaceFamInst :: FamInst -> IfaceFamInst famInstToIfaceFamInst (FamInst { fi_axiom = axiom, fi_fam = fam, fi_tcs = roughs }) = IfaceFamInst { ifFamInstAxiom = coAxiomName axiom , ifFamInstFam = fam , ifFamInstTys = map do_rough roughs , ifFamInstOrph = orph } where do_rough Nothing = Nothing do_rough (Just n) = Just (toIfaceTyCon_name n) fam_decl = tyConName $ coAxiomTyCon axiom mod = ASSERT( isExternalName (coAxiomName axiom) ) nameModule (coAxiomName axiom) is_local name = nameIsLocalOrFrom mod name lhs_names = filterNameSet is_local (orphNamesOfCoCon axiom) orph | is_local fam_decl = NotOrphan (nameOccName fam_decl) | otherwise = chooseOrphanAnchor lhs_names -------------------------- toIfaceLetBndr :: Id -> IfaceLetBndr toIfaceLetBndr id = IfLetBndr (occNameFS (getOccName id)) (toIfaceType (idType id)) (toIfaceIdInfo (idInfo id)) -- Put into the interface file any IdInfo that CoreTidy.tidyLetBndr -- has left on the Id. See Note [IdInfo on nested let-bindings] in IfaceSyn --------------------------t toIfaceIdDetails :: IdDetails -> IfaceIdDetails toIfaceIdDetails VanillaId = IfVanillaId toIfaceIdDetails (DFunId {}) = IfDFunId toIfaceIdDetails (RecSelId { sel_naughty = n , sel_tycon = tc }) = let iface = case tc of RecSelData ty_con -> Left (toIfaceTyCon ty_con) RecSelPatSyn pat_syn -> Right (patSynToIfaceDecl pat_syn) in IfRecSelId iface n -- The remaining cases are all "implicit Ids" which don't -- appear in interface files at all toIfaceIdDetails other = pprTrace "toIfaceIdDetails" (ppr other) IfVanillaId -- Unexpected; the other toIfaceIdInfo :: IdInfo -> IfaceIdInfo toIfaceIdInfo id_info = case catMaybes [arity_hsinfo, caf_hsinfo, strict_hsinfo, inline_hsinfo, unfold_hsinfo] of [] -> NoInfo infos -> HasInfo infos -- NB: strictness and arity must appear in the list before unfolding -- See TcIface.tcUnfolding where ------------ Arity -------------- arity_info = arityInfo id_info arity_hsinfo | arity_info == 0 = Nothing | otherwise = Just (HsArity arity_info) ------------ Caf Info -------------- caf_info = cafInfo id_info caf_hsinfo = case caf_info of NoCafRefs -> Just HsNoCafRefs _other -> Nothing ------------ Strictness -------------- -- No point in explicitly exporting TopSig sig_info = strictnessInfo id_info strict_hsinfo | not (isTopSig sig_info) = Just (HsStrictness sig_info) | otherwise = Nothing ------------ Unfolding -------------- unfold_hsinfo = toIfUnfolding loop_breaker (unfoldingInfo id_info) loop_breaker = isStrongLoopBreaker (occInfo id_info) ------------ Inline prag -------------- inline_prag = inlinePragInfo id_info inline_hsinfo | isDefaultInlinePragma inline_prag = Nothing | otherwise = Just (HsInline inline_prag) -------------------------- toIfUnfolding :: Bool -> Unfolding -> Maybe IfaceInfoItem toIfUnfolding lb (CoreUnfolding { uf_tmpl = rhs , uf_src = src , uf_guidance = guidance }) = Just $ HsUnfold lb $ case src of InlineStable -> case guidance of UnfWhen {ug_arity = arity, ug_unsat_ok = unsat_ok, ug_boring_ok = boring_ok } -> IfInlineRule arity unsat_ok boring_ok if_rhs _other -> IfCoreUnfold True if_rhs InlineCompulsory -> IfCompulsory if_rhs InlineRhs -> IfCoreUnfold False if_rhs -- Yes, even if guidance is UnfNever, expose the unfolding -- If we didn't want to expose the unfolding, TidyPgm would -- have stuck in NoUnfolding. For supercompilation we want -- to see that unfolding! where if_rhs = toIfaceExpr rhs toIfUnfolding lb (DFunUnfolding { df_bndrs = bndrs, df_args = args }) = Just (HsUnfold lb (IfDFunUnfold (map toIfaceBndr bndrs) (map toIfaceExpr args))) -- No need to serialise the data constructor; -- we can recover it from the type of the dfun toIfUnfolding _ _ = Nothing -------------------------- coreRuleToIfaceRule :: CoreRule -> IfaceRule coreRuleToIfaceRule (BuiltinRule { ru_fn = fn}) = pprTrace "toHsRule: builtin" (ppr fn) $ bogusIfaceRule fn coreRuleToIfaceRule (Rule { ru_name = name, ru_fn = fn, ru_act = act, ru_bndrs = bndrs, ru_args = args, ru_rhs = rhs, ru_orphan = orph, ru_auto = auto }) = IfaceRule { ifRuleName = name, ifActivation = act, ifRuleBndrs = map toIfaceBndr bndrs, ifRuleHead = fn, ifRuleArgs = map do_arg args, ifRuleRhs = toIfaceExpr rhs, ifRuleAuto = auto, ifRuleOrph = orph } where -- For type args we must remove synonyms from the outermost -- level. Reason: so that when we read it back in we'll -- construct the same ru_rough field as we have right now; -- see tcIfaceRule do_arg (Type ty) = IfaceType (toIfaceType (deNoteType ty)) do_arg (Coercion co) = IfaceCo (toIfaceCoercion co) do_arg arg = toIfaceExpr arg bogusIfaceRule :: Name -> IfaceRule bogusIfaceRule id_name = IfaceRule { ifRuleName = fsLit "bogus", ifActivation = NeverActive, ifRuleBndrs = [], ifRuleHead = id_name, ifRuleArgs = [], ifRuleRhs = IfaceExt id_name, ifRuleOrph = IsOrphan, ifRuleAuto = True } --------------------- toIfaceExpr :: CoreExpr -> IfaceExpr toIfaceExpr (Var v) = toIfaceVar v toIfaceExpr (Lit l) = IfaceLit l toIfaceExpr (Type ty) = IfaceType (toIfaceType ty) toIfaceExpr (Coercion co) = IfaceCo (toIfaceCoercion co) toIfaceExpr (Lam x b) = IfaceLam (toIfaceBndr x, toIfaceOneShot x) (toIfaceExpr b) toIfaceExpr (App f a) = toIfaceApp f [a] toIfaceExpr (Case s x ty as) | null as = IfaceECase (toIfaceExpr s) (toIfaceType ty) | otherwise = IfaceCase (toIfaceExpr s) (getOccFS x) (map toIfaceAlt as) toIfaceExpr (Let b e) = IfaceLet (toIfaceBind b) (toIfaceExpr e) toIfaceExpr (Cast e co) = IfaceCast (toIfaceExpr e) (toIfaceCoercion co) toIfaceExpr (Tick t e) | Just t' <- toIfaceTickish t = IfaceTick t' (toIfaceExpr e) | otherwise = toIfaceExpr e toIfaceOneShot :: Id -> IfaceOneShot toIfaceOneShot id | isId id , OneShotLam <- oneShotInfo (idInfo id) = IfaceOneShot | otherwise = IfaceNoOneShot --------------------- toIfaceTickish :: Tickish Id -> Maybe IfaceTickish toIfaceTickish (ProfNote cc tick push) = Just (IfaceSCC cc tick push) toIfaceTickish (HpcTick modl ix) = Just (IfaceHpcTick modl ix) toIfaceTickish (SourceNote src names) = Just (IfaceSource src names) toIfaceTickish (Breakpoint {}) = Nothing -- Ignore breakpoints, since they are relevant only to GHCi, and -- should not be serialised (Trac #8333) --------------------- toIfaceBind :: Bind Id -> IfaceBinding toIfaceBind (NonRec b r) = IfaceNonRec (toIfaceLetBndr b) (toIfaceExpr r) toIfaceBind (Rec prs) = IfaceRec [(toIfaceLetBndr b, toIfaceExpr r) | (b,r) <- prs] --------------------- toIfaceAlt :: (AltCon, [Var], CoreExpr) -> (IfaceConAlt, [FastString], IfaceExpr) toIfaceAlt (c,bs,r) = (toIfaceCon c, map getOccFS bs, toIfaceExpr r) --------------------- toIfaceCon :: AltCon -> IfaceConAlt toIfaceCon (DataAlt dc) = IfaceDataAlt (getName dc) toIfaceCon (LitAlt l) = IfaceLitAlt l toIfaceCon DEFAULT = IfaceDefault --------------------- toIfaceApp :: Expr CoreBndr -> [Arg CoreBndr] -> IfaceExpr toIfaceApp (App f a) as = toIfaceApp f (a:as) toIfaceApp (Var v) as = case isDataConWorkId_maybe v of -- We convert the *worker* for tuples into IfaceTuples Just dc | saturated , Just tup_sort <- tyConTuple_maybe tc -> IfaceTuple tup_sort tup_args where val_args = dropWhile isTypeArg as saturated = val_args `lengthIs` idArity v tup_args = map toIfaceExpr val_args tc = dataConTyCon dc _ -> mkIfaceApps (toIfaceVar v) as toIfaceApp e as = mkIfaceApps (toIfaceExpr e) as mkIfaceApps :: IfaceExpr -> [CoreExpr] -> IfaceExpr mkIfaceApps f as = foldl (\f a -> IfaceApp f (toIfaceExpr a)) f as --------------------- toIfaceVar :: Id -> IfaceExpr toIfaceVar v | Just fcall <- isFCallId_maybe v = IfaceFCall fcall (toIfaceType (idType v)) -- Foreign calls have special syntax | isBootUnfolding (idUnfolding v) = IfaceApp (IfaceApp (IfaceExt noinlineIdName) (IfaceType (toIfaceType (idType v)))) (IfaceExt name) -- don't use mkIfaceApps, or infinite loop -- See Note [Inlining and hs-boot files] | isExternalName name = IfaceExt name | otherwise = IfaceLcl (getOccFS name) where name = idName v {- Note [Inlining and hs-boot files] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider this example (Trac #10083): ---------- RSR.hs-boot ------------ module RSR where data RSR eqRSR :: RSR -> RSR -> Bool ---------- SR.hs ------------ module SR where import {-# SOURCE #-} RSR data SR = MkSR RSR eqSR (MkSR r1) (MkSR r2) = eqRSR r1 r2 ---------- RSR.hs ------------ module RSR where import SR data RSR = MkRSR SR -- deriving( Eq ) eqRSR (MkRSR s1) (MkRSR s2) = (eqSR s1 s2) foo x y = not (eqRSR x y) When compiling RSR we get this code RSR.eqRSR :: RSR -> RSR -> Bool RSR.eqRSR = \ (ds1 :: RSR.RSR) (ds2 :: RSR.RSR) -> case ds1 of _ { RSR.MkRSR s1 -> case ds2 of _ { RSR.MkRSR s2 -> SR.eqSR s1 s2 }} RSR.foo :: RSR -> RSR -> Bool RSR.foo = \ (x :: RSR) (y :: RSR) -> not (RSR.eqRSR x y) Now, when optimising foo: Inline eqRSR (small, non-rec) Inline eqSR (small, non-rec) but the result of inlining eqSR from SR is another call to eqRSR, so everything repeats. Neither eqSR nor eqRSR are (apparently) loop breakers. Solution: in the unfolding of eqSR in SR.hi, replace `eqRSR` in SR with `noinline eqRSR`, so that eqRSR doesn't get inlined. This means that when GHC inlines `eqSR`, it will not also inline `eqRSR`, exactly as would have been the case if `foo` had been defined in SR.hs (and marked as a loop-breaker). But how do we arrange for this to happen? There are two ingredients: 1. When we serialize out unfoldings to IfaceExprs (toIfaceVar), for every variable reference we see if we are referring to an 'Id' that came from an hs-boot file. If so, we add a `noinline` to the reference. 2. But how do we know if a reference came from an hs-boot file or not? We could record this directly in the 'IdInfo', but actually we deduce this by looking at the unfolding: 'Id's that come from boot files are given a special unfolding (upon typechecking) 'BootUnfolding' which say that there is no unfolding, and the reason is because the 'Id' came from a boot file. Here is a solution that doesn't work: when compiling RSR, add a NOINLINE pragma to every function exported by the boot-file for RSR (if it exists). Doing so makes the bootstrapped GHC itself slower by 8% overall (on Trac #9872a-d, and T1969: the reason is that these NOINLINE'd functions now can't be profitably inlined outside of the hs-boot loop. -}
snoyberg/ghc
compiler/iface/MkIface.hs
bsd-3-clause
84,065
3
24
26,295
14,587
7,647
6,940
-1
-1
{-# LANGUAGE GADTs #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} -- -- Copyright (c) 2009-2011, ERICSSON AB -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without -- modification, are permitted provided that the following conditions are met: -- -- * Redistributions of source code must retain the above copyright notice, -- this list of conditions and the following disclaimer. -- * Redistributions in binary form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- * Neither the name of the ERICSSON AB nor the names of its contributors -- may be used to endorse or promote products derived from this software -- without specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- module Feldspar.Core.Constructs.MutableArray (MutableArray(..)) where import Control.Monad import Data.Array.IO import Language.Syntactic import Language.Syntactic.Constructs.Binding import Feldspar.Lattice import Feldspar.Core.Types import Feldspar.Core.Interpretation data MutableArray a where NewArr :: Type a => MutableArray (Length :-> a :-> Full (Mut (MArr a))) NewArr_ :: Type a => MutableArray (Length :-> Full (Mut (MArr a))) GetArr :: Type a => MutableArray (MArr a :-> Index :-> Full (Mut a)) SetArr :: MutableArray (MArr a :-> Index :-> a :-> Full (Mut ())) ArrLength :: MutableArray (MArr a :-> Full (Mut Length)) -- TODO Should be pure? instance Semantic MutableArray where semantics NewArr = Sem "newMArr" $ \l -> newArray (mkBounds $ toInteger l) semantics NewArr_ = Sem "newMArr_" $ \l -> newListArray (mkBounds $ toInteger l) [error $ "Undefined element at index " ++ show (i::Integer) | i <- [0..]] semantics GetArr = Sem "getMArr" $ \arr i -> readArray arr (toInteger i) semantics SetArr = Sem "setMArr" $ \arr i -> writeArray arr (toInteger i) semantics ArrLength = Sem "arrLength" (getBounds >=> \(l,u) -> return $ fromInteger (u-l+1)) -- | Calculate array bounds. If the length is zero, flip the arguments to -- make an empty range mkBounds :: Integer -> (Integer,Integer) mkBounds l = (0, pred l) semanticInstances ''MutableArray instance EvalBind MutableArray where evalBindSym = evalBindSymDefault instance AlphaEq dom dom dom env => AlphaEq MutableArray MutableArray dom env where alphaEqSym = alphaEqSymDefault instance Sharable MutableArray instance Cumulative MutableArray instance SizeProp MutableArray where sizeProp NewArr (WrapFull len :* _ :* Nil) = infoSize len :> universal -- Note: The length isn't mutable, so it can be given a non-universal size. sizeProp NewArr_ (WrapFull len :* Nil) = infoSize len :> universal sizeProp GetArr _ = universal sizeProp SetArr _ = universal sizeProp ArrLength (WrapFull arr :* Nil) = len where len :> _ = infoSize arr instance (MutableArray :<: dom, Optimize dom dom) => Optimize MutableArray dom where constructFeatUnOpt opts NewArr args = constructFeatUnOptDefaultTyp opts (MutType $ MArrType typeRep) NewArr args constructFeatUnOpt opts NewArr_ args = constructFeatUnOptDefaultTyp opts (MutType $ MArrType typeRep) NewArr_ args constructFeatUnOpt opts GetArr args = constructFeatUnOptDefaultTyp opts (MutType typeRep) GetArr args constructFeatUnOpt opts SetArr args = constructFeatUnOptDefaultTyp opts (MutType typeRep) SetArr args constructFeatUnOpt opts ArrLength args = constructFeatUnOptDefaultTyp opts (MutType typeRep) ArrLength args
emwap/feldspar-language
src/Feldspar/Core/Constructs/MutableArray.hs
bsd-3-clause
4,719
0
14
939
895
473
422
51
1
module Rho.Bitfield where import Control.Monad import qualified Data.Bits as B import qualified Data.ByteString as B import qualified Data.Set as S import qualified Data.Vector.Storable as SV import qualified Data.Vector.Storable.Mutable as MV import Data.Word import Rho.Utils data Bitfield = Bitfield (MV.IOVector Word8) Int instance Show Bitfield where show (Bitfield _ len) = "<bitfield of length " ++ show len ++ ">" -- | Create a bitfield of given length. -- -- >>> availableBits =<< empty 5 -- fromList [] -- -- >>> missingBits =<< empty 5 -- fromList [0,1,2,3,4] -- empty :: Int -> IO Bitfield empty len = do let (d, m) = len `divMod` 8 v <- MV.replicate (if m == 0 then d else d + 1) 0 return $ Bitfield v len -- | Create a bitfield of given length, with all bits set. -- -- >>> missingBits =<< full 5 -- fromList [] -- full :: Int -> IO Bitfield full len = do let (d, m) = len `divMod` 8 v <- MV.replicate (if m == 0 then d else d + 1) 0xFF return $ Bitfield v len length :: Bitfield -> Int length (Bitfield _ len) = len -- | Create a bitfield from given bytestring and length. -- -- >>> availableBits =<< fromBS (B.pack [0, 1]) 16 -- fromList [15] -- -- >>> availableBits =<< fromBS (B.pack [128, 0]) 16 -- fromList [0] -- fromBS :: B.ByteString -> Int -> IO Bitfield fromBS bs len = do v <- SV.unsafeThaw (bsToByteVector (B.copy bs)) return $ Bitfield v len -- | Create a ByteString from given Bitfield. Extra bits in the generated -- ByteString will be 0. toBS :: Bitfield -> IO B.ByteString toBS (Bitfield v _) = bsFromByteVector `fmap` SV.freeze v -- | Create a bitfield from given bit indexes and length. -- -- >>> availableBits =<< fromBitIdxs [1, 3, 5, 10] 10 -- fromList [1,3,5] -- fromBitIdxs :: [Int] -> Int -> IO Bitfield fromBitIdxs idxs len = do bf@(Bitfield v _) <- empty len iter v idxs return bf where iter :: MV.IOVector Word8 -> [Int] -> IO () iter _ [] = return () iter v (i : is) | i >= len = iter v is | otherwise = do let byteIdx = i `div` 8 bitIdx = 7 - (i `mod` 8) b <- MV.unsafeRead v byteIdx MV.unsafeWrite v byteIdx (B.setBit b bitIdx) iter v is test :: Bitfield -> Int -> IO Bool test (Bitfield v len) i | i > len - 1 = error $ "trying to test an invalid bit. (length: " ++ show len ++ ", bit idx: " ++ show i ++ ")" | otherwise = do let byteIdx = i `div` 8 bitIdx = 7 - (i `mod` 8) byte <- MV.unsafeRead v byteIdx return $ B.testBit byte bitIdx set :: Bitfield -> Int -> IO () set (Bitfield v len) i | i > len - 1 = error $ "trying to set an invalid bit. (length: " ++ show len ++ ", bit idx: " ++ show i ++ ")" | otherwise = do let byteIdx = i `div` 8 bitIdx = 7 - (i `mod` 8) byte <- MV.unsafeRead v byteIdx MV.unsafeWrite v byteIdx (B.setBit byte bitIdx) -- | Generate set of indexes of zero bits. -- -- >>> missingBits =<< fromBS (B.pack [1, 2, 3]) 20 -- fromList [0,1,2,3,4,5,6,8,9,10,11,12,13,15,16,17,18,19] -- -- >>> missingBits =<< fromBS (B.pack [0xFF]) 8 -- fromList [] -- -- >>> missingBits =<< fromBS (B.pack []) 0 -- fromList [] -- missingBits :: Bitfield -> IO (S.Set Int) missingBits = collectBits not -- | Effectively same as checking if `missingBits` is empty, but faster. -- -- >>> hasMissingBits =<< fromBS (B.pack [0xFF]) 8 -- False -- -- >>> hasMissingBits =<< fromBS (B.pack [0xFF - 1]) 8 -- True -- hasMissingBits :: Bitfield -> IO Bool hasMissingBits bits@(Bitfield bf len) = go 0 where go idx | idx == len = return False | otherwise = do b <- test bits idx if b then go (idx + 1) else return True -- | Generate set of indexes of one bits. -- -- >>> availableBits =<< fromBS (B.pack [1, 2, 3]) 20 -- fromList [7,14] -- -- >>> availableBits =<< fromBS (B.pack [0xFF]) 8 -- fromList [0,1,2,3,4,5,6,7] -- -- >>> availableBits =<< fromBS (B.pack []) 0 -- fromList [] -- availableBits :: Bitfield -> IO (S.Set Int) availableBits = collectBits id -- | Check all bits in range. Out-of-range bits are considered set. Return -- True if `start` >= `end`. -- -- >>> (\bf -> checkRange bf 5 10) =<< fromBitIdxs [5..9] 10 -- True -- checkRange :: Bitfield -> Int -> Int -> IO Bool checkRange bits@(Bitfield _ len) start end | start >= min len end = return True | otherwise = do b <- test bits start if b then checkRange bits (start + 1) end else return False collectBits :: (Bool -> Bool) -> Bitfield -> IO (S.Set Int) collectBits p bf@(Bitfield _ len) = S.fromList `fmap` filterM (p <.> test bf) [0..len-1] {-# INLINE collectBits #-}
osa1/rho-torrent
src/Rho/Bitfield.hs
bsd-3-clause
4,787
0
15
1,246
1,366
717
649
85
2
{-# LANGUAGE GADTs, RecordWildCards, FlexibleContexts, TemplateHaskell #-} module YaLedger.Processor.Rules (runRules) where import Control.Monad.State import Control.Monad.Exception import Data.Maybe import Data.Decimal import Data.Hashable import qualified Data.Map as M import Data.Dates import Text.Printf import YaLedger.Types import YaLedger.Exceptions import YaLedger.Kernel import YaLedger.Processor.Templates import YaLedger.Logger -- | Check if posting matches to 'Condition' matchC :: (Throws NoSuchRate l, Throws InternalError l) => M.Map AccountID [GroupID] -- ^ Precomputed map of account groups -> DateTime -- ^ Posting date/time -> Posting Decimal t -- ^ Posting itself -> Condition -> Atomic l Bool matchC groupsMap date (CPosting acc x _) cond = check groupsMap ECredit date acc x cond matchC groupsMap date (DPosting acc x _) cond = check groupsMap EDebit date acc x cond check :: (Throws NoSuchRate l, Throws InternalError l, HasID a, HasCurrency a) => M.Map AccountID [GroupID] -- ^ Precomputed map of account groups -> PostingType -> DateTime -> a -> Decimal -> Condition -> Atomic l Bool check groupsMap t date acc x (Condition {..}) = do let accID = getID acc let grps = fromMaybe [] $ M.lookup accID groupsMap action = maybe [ECredit, EDebit] (\x -> [x]) cAction if (t `elem` action) && ((accID `elem` cAccounts) || (any (`elem` cGroups) grps)) then do let accountCurrency = getCurrency acc if cValue == AnyValue then return True else do let (op, v) = case cValue of MoreThan s -> ((>), s) LessThan s -> ((<), s) Equals s -> ((==), s) _ -> error "Processor.Rules.matchC.check: Impossible." condValue :# _ <- convert (Just date) defaultRatesGroup accountCurrency v return $ x `op` condValue else do $debugSTM (printf "Action: %s (%s), accID: %s (%s)" (show t) (show action) (show accID) (show cAccounts)) return False -- | Apply given function to all transactions which are -- produced by all rules, applicable for this posting runRules :: (Throws NoSuchRate l, Throws NoCorrespondingAccountFound l, Throws InvalidAccountType l, Throws NoSuchTemplate l, Throws InternalError l) => PostingType -> DateTime -- ^ Date/time of the posting -> Integer -> Attributes -- ^ Posting attributes -> Posting Decimal t -- ^ Posting itself -> (Integer -> Ext (Transaction Amount) -> Atomic l ()) -- ^ Function to apply to produced transactions -> Atomic l () runRules pt date tranID pAttrs p run = do rules <- gets (case pt of ECredit -> creditRules . lsRules EDebit -> debitRules . lsRules ) $infoSTM $ "Rules: " ++ show pt ++ ": " ++ unwords [n | (n,_,_) <- rules] groupsMap <- gets lsFullGroupsMap let ns = enumFrom (tranID + 1) t <- forM (zip ns rules) $ \(i, (name, attrs, When cond tran)) -> do y <- matchC groupsMap date p cond $debugSTM $ "Checking rule " ++ name ++ ", account/action match: " ++ show y if y && (pAttrs `matchAll` cAttributes cond) then do let attrs' = M.insert "rule" (Exactly name) (pAttrs `M.union` attrs) (c, x) = case p of DPosting acc x _ -> (getCurrency acc, x) CPosting acc x _ -> (getCurrency acc, x) $infoSTM $ "Applying rule " ++ name tran' <- liftTemplate $ fillTemplate tran [x :# c] let pos = newPos ("<generated by rule \"" ++ name ++ "\">") 0 0 return [(name, i, Ext date (fromIntegral $ hash p) pos attrs' tran')] else return [] let rs = concat t forM_ rs $ \(name, i, extTran) -> do $infoSTM $ "Firing rule " ++ name run i extTran
portnov/yaledger
YaLedger/Processor/Rules.hs
bsd-3-clause
4,174
0
22
1,356
1,262
650
612
91
6
module Lib ( hagentoMain ) where import Args (Options(..)) import qualified Args import qualified Xml import qualified Magento hagentoMain :: IO () hagentoMain = Args.argsParser run run :: Options -> IO () run opts@Options { optRoot = root, subCommand = Args.XmlListFiles } = do putStrLn $ show opts files <- Xml.getXmlFiles root putStrLn $ show files --map putStrLn files
dxtr/hagento
src/Lib.hs
bsd-3-clause
392
0
10
78
128
70
58
13
1
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE UndecidableInstances #-} module Cabal.Config ( -- * Types Config (..), Repo (..), RepoName, -- * Parsing readConfig, findConfig, parseConfig, resolveConfig, -- * Hackage cfgRepoIndex, hackageHaskellOrg, ) where import Control.DeepSeq (NFData (..)) import Control.Exception (throwIO) import Data.ByteString (ByteString) import Data.Function ((&)) import Data.Functor.Identity (Identity (..)) import Data.List (foldl') import Data.List.NonEmpty (NonEmpty) import Data.Map (Map) import Data.Maybe (fromMaybe) import Distribution.Compat.Lens (LensLike', over) import GHC.Generics (Generic) import Network.URI (URI) import System.Directory (getAppUserDataDirectory) import System.Environment (lookupEnv) import System.FilePath ((</>)) import qualified Data.ByteString as BS import qualified Data.Map.Strict as M import qualified Distribution.CabalSpecVersion as C import qualified Distribution.FieldGrammar as C import qualified Distribution.Fields as C import qualified Distribution.Parsec as C import qualified Distribution.Simple.Utils as C import Cabal.Internal.Newtypes import Cabal.Parse infixl 1 <&> (<&>) :: Functor f => f a -> (a -> b) -> f b (<&>) = flip fmap ------------------------------------------------------------------------------- -- Read config ------------------------------------------------------------------------------- -- | High level convenience function to find and read @~\/.cabal\/config@ file -- -- May throw 'IOException' when file doesn't exist, and 'ParseError' -- on parse error. -- readConfig :: IO (Config Identity) readConfig = do fp <- findConfig bs <- BS.readFile fp either throwIO resolveConfig (parseConfig fp bs) ------------------------------------------------------------------------------- -- Find config ------------------------------------------------------------------------------- -- | Find the @~\/.cabal\/config@ file. findConfig :: IO FilePath findConfig = do env <- lookupEnv "CABAL_CONFIG" case env of Just p -> return p Nothing -> do cabalDirVar <- lookupEnv "CABAL_DIR" cabalDir <- maybe (getAppUserDataDirectory "cabal") return cabalDirVar return (cabalDir </> "config") ------------------------------------------------------------------------------- -- Config ------------------------------------------------------------------------------- -- | Very minimal representation of @~\/.cabal\/config@ file. data Config f = Config { cfgRepositories :: Map RepoName Repo , cfgRemoteRepoCache :: f FilePath , cfgInstallDir :: f FilePath , cfgStoreDir :: f FilePath } deriving (Generic) deriving instance Show (f FilePath) => Show (Config f) -- | @since 0.2.1 instance NFData (f FilePath) => NFData (Config f) -- | Repository. -- -- missing @root-keys@, @key-threshold@ which we don't need now. -- data Repo = Repo { repoURL :: URI , repoSecure :: Bool -- ^ @since 0.2 } deriving (Show, Generic) -- | Repository name, bare 'String'. type RepoName = String -- | @since 0.2.1 instance NFData Repo ------------------------------------------------------------------------------- -- Finding index ------------------------------------------------------------------------------- -- | Find a @01-index.tar@ for particular repository cfgRepoIndex :: Config Identity -> RepoName -> Maybe FilePath cfgRepoIndex cfg repo | repo `M.member` cfgRepositories cfg = Just (runIdentity (cfgRemoteRepoCache cfg) </> repo </> "01-index.tar") | otherwise = Nothing -- | The default repository of haskell packages, <https://hackage.haskell.org/>. hackageHaskellOrg :: RepoName hackageHaskellOrg = "hackage.haskell.org" ------------------------------------------------------------------------------- -- Parsing ------------------------------------------------------------------------------- -- | Parse @~\/.cabal\/config@ file. parseConfig :: FilePath -> ByteString -> Either (ParseError NonEmpty) (Config Maybe) parseConfig = parseWith $ \fields0 -> do let (fields1, sections) = C.partitionFields fields0 let fields2 = M.filterWithKey (\k _ -> k `elem` knownFields) fields1 parse fields2 sections where knownFields = C.fieldGrammarKnownFieldList grammar parse fields sections = do cfg <- C.parseFieldGrammar C.cabalSpecLatest fields grammar foldl' (&) cfg <$> traverse parseSec (concat sections) parseSec :: C.Section C.Position -> C.ParseResult (Config f -> Config f) parseSec (C.MkSection (C.Name _pos name) [C.SecArgName _pos' secName] fields) | name == "repository" = do let repoName = C.fromUTF8BS secName let fields' = fst $ C.partitionFields fields repo <- C.parseFieldGrammar C.cabalSpecLatest fields' repoGrammar return $ over cfgRepositoriesL $ M.insert repoName repo parseSec _ = return id grammar :: C.ParsecFieldGrammar (Config Maybe) (Config Maybe) grammar = Config mempty <$> C.optionalFieldAla "remote-repo-cache" C.FilePathNT cfgRemoteRepoCacheL <*> C.optionalFieldAla "installdir" C.FilePathNT cfgInstallDirL <*> C.optionalFieldAla "store-dir" C.FilePathNT cfgStoreDirL repoGrammar :: C.ParsecFieldGrammar Repo Repo repoGrammar = Repo <$> C.uniqueFieldAla "url" WrapURI repoURLL <*> C.booleanFieldDef "secure" repoSecureL False ------------------------------------------------------------------------------- -- Resolving ------------------------------------------------------------------------------- -- | Fill the default in @~\/.cabal\/config@ file. resolveConfig :: Config Maybe -> IO (Config Identity) resolveConfig cfg = do c <- getAppUserDataDirectory "cabal" return cfg { cfgRemoteRepoCache = Identity $ fromMaybe (c </> "packages") (cfgRemoteRepoCache cfg) , cfgInstallDir = Identity $ fromMaybe (c </> "bin") (cfgInstallDir cfg) , cfgStoreDir = Identity $ fromMaybe (c </> "store") (cfgStoreDir cfg) } ------------------------------------------------------------------------------- -- Lenses ------------------------------------------------------------------------------- cfgRepositoriesL :: Functor f => LensLike' f (Config g) (Map String Repo) cfgRepositoriesL f cfg = f (cfgRepositories cfg) <&> \x -> cfg { cfgRepositories = x } cfgRemoteRepoCacheL :: Functor f => LensLike' f (Config g) (g FilePath) cfgRemoteRepoCacheL f cfg = f (cfgRemoteRepoCache cfg) <&> \x -> cfg { cfgRemoteRepoCache = x } cfgInstallDirL :: Functor f => LensLike' f (Config g) (g FilePath) cfgInstallDirL f cfg = f (cfgInstallDir cfg) <&> \x -> cfg { cfgInstallDir = x } cfgStoreDirL :: Functor f => LensLike' f (Config g) (g FilePath) cfgStoreDirL f cfg = f (cfgStoreDir cfg) <&> \x -> cfg { cfgStoreDir = x } repoURLL :: Functor f => LensLike' f Repo URI repoURLL f s = f (repoURL s) <&> \x -> s { repoURL = x } repoSecureL :: Functor f => LensLike' f Repo Bool repoSecureL f s = f (repoSecure s) <&> \x -> s { repoSecure = x }
hvr/multi-ghc-travis
cabal-install-parsers/src/Cabal/Config.hs
bsd-3-clause
7,443
0
15
1,492
1,733
929
804
-1
-1
-- | -- -- Utils for using aeson's deriveJSON with lens's makeFields module Data.Aeson.APIFieldJsonTH ( -- * How to use this library -- $use deriveApiFieldJSON ) where import Prelude import Data.Aeson.TH import qualified Data.Char as C (toLower) import Language.Haskell.TH (Q, Dec, Name, nameBase) -- $use -- -- > data SomeQuery = SomeQuery { -- > _someQueryPage :: Int -- > , _someQueryText :: String -- > } deriving (Eq, Show) -- > makeFields ''SomeQuery -- > deriveApiFieldJSON ''SomeQuery -- -- This is compatible with the next json: -- -- > {"page": 3, "text": "foo"} -- -- | Derive a JSON instance like 'Control.Lens.TH.makeFields': -- Drop the type's name prefix from each record labels. deriveApiFieldJSON :: Name -> Q [Dec] deriveApiFieldJSON name = deriveJSON defaultOptions { fieldLabelModifier = firstLower . dropPrefix name } name firstLower :: String -> String firstLower (x:xs) = C.toLower x : xs firstLower _ = error "firstLower: Assertion failed: empty string" dropPrefix :: Name -> String -> String dropPrefix name = drop ((+ 1) $ length $ nameBase name)
nakaji-dayo/api-field-json-th
Data/Aeson/APIFieldJsonTH.hs
bsd-3-clause
1,108
0
9
207
203
122
81
14
1
{-# LANGUAGE BangPatterns, DeriveDataTypeable, DeriveGeneric, FlexibleInstances, MultiParamTypeClasses #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-} module Web.RTBBidder.Protocol.Adx.BidRequest.PublisherType (PublisherType(..)) where import Prelude ((+), (/), (.)) import qualified Prelude as Prelude' import qualified Data.Typeable as Prelude' import qualified GHC.Generics as Prelude' import qualified Data.Data as Prelude' import qualified Text.ProtocolBuffers.Header as P' data PublisherType = UNKNOWN_PUBLISHER_TYPE | ADX_PUBLISHER_OWNED_AND_OPERATED | ADX_PUBLISHER_REPRESENTED | GOOGLE_REPRESENTED deriving (Prelude'.Read, Prelude'.Show, Prelude'.Eq, Prelude'.Ord, Prelude'.Typeable, Prelude'.Data, Prelude'.Generic) instance P'.Mergeable PublisherType instance Prelude'.Bounded PublisherType where minBound = UNKNOWN_PUBLISHER_TYPE maxBound = GOOGLE_REPRESENTED instance P'.Default PublisherType where defaultValue = UNKNOWN_PUBLISHER_TYPE toMaybe'Enum :: Prelude'.Int -> P'.Maybe PublisherType toMaybe'Enum 0 = Prelude'.Just UNKNOWN_PUBLISHER_TYPE toMaybe'Enum 1 = Prelude'.Just ADX_PUBLISHER_OWNED_AND_OPERATED toMaybe'Enum 2 = Prelude'.Just ADX_PUBLISHER_REPRESENTED toMaybe'Enum 3 = Prelude'.Just GOOGLE_REPRESENTED toMaybe'Enum _ = Prelude'.Nothing instance Prelude'.Enum PublisherType where fromEnum UNKNOWN_PUBLISHER_TYPE = 0 fromEnum ADX_PUBLISHER_OWNED_AND_OPERATED = 1 fromEnum ADX_PUBLISHER_REPRESENTED = 2 fromEnum GOOGLE_REPRESENTED = 3 toEnum = P'.fromMaybe (Prelude'.error "hprotoc generated code: toEnum failure for type Web.RTBBidder.Protocol.Adx.BidRequest.PublisherType") . toMaybe'Enum succ UNKNOWN_PUBLISHER_TYPE = ADX_PUBLISHER_OWNED_AND_OPERATED succ ADX_PUBLISHER_OWNED_AND_OPERATED = ADX_PUBLISHER_REPRESENTED succ ADX_PUBLISHER_REPRESENTED = GOOGLE_REPRESENTED succ _ = Prelude'.error "hprotoc generated code: succ failure for type Web.RTBBidder.Protocol.Adx.BidRequest.PublisherType" pred ADX_PUBLISHER_OWNED_AND_OPERATED = UNKNOWN_PUBLISHER_TYPE pred ADX_PUBLISHER_REPRESENTED = ADX_PUBLISHER_OWNED_AND_OPERATED pred GOOGLE_REPRESENTED = ADX_PUBLISHER_REPRESENTED pred _ = Prelude'.error "hprotoc generated code: pred failure for type Web.RTBBidder.Protocol.Adx.BidRequest.PublisherType" instance P'.Wire PublisherType where wireSize ft' enum = P'.wireSize ft' (Prelude'.fromEnum enum) wirePut ft' enum = P'.wirePut ft' (Prelude'.fromEnum enum) wireGet 14 = P'.wireGetEnum toMaybe'Enum wireGet ft' = P'.wireGetErr ft' wireGetPacked 14 = P'.wireGetPackedEnum toMaybe'Enum wireGetPacked ft' = P'.wireGetErr ft' instance P'.GPB PublisherType instance P'.MessageAPI msg' (msg' -> PublisherType) PublisherType where getVal m' f' = f' m' instance P'.ReflectEnum PublisherType where reflectEnum = [(0, "UNKNOWN_PUBLISHER_TYPE", UNKNOWN_PUBLISHER_TYPE), (1, "ADX_PUBLISHER_OWNED_AND_OPERATED", ADX_PUBLISHER_OWNED_AND_OPERATED), (2, "ADX_PUBLISHER_REPRESENTED", ADX_PUBLISHER_REPRESENTED), (3, "GOOGLE_REPRESENTED", GOOGLE_REPRESENTED)] reflectEnumInfo _ = P'.EnumInfo (P'.makePNF (P'.pack ".Adx.BidRequest.PublisherType") ["Web", "RTBBidder", "Protocol"] ["Adx", "BidRequest"] "PublisherType") ["Web", "RTBBidder", "Protocol", "Adx", "BidRequest", "PublisherType.hs"] [(0, "UNKNOWN_PUBLISHER_TYPE"), (1, "ADX_PUBLISHER_OWNED_AND_OPERATED"), (2, "ADX_PUBLISHER_REPRESENTED"), (3, "GOOGLE_REPRESENTED")] instance P'.TextType PublisherType where tellT = P'.tellShow getT = P'.getRead
hiratara/hs-rtb-bidder
src/Web/RTBBidder/Protocol/Adx/BidRequest/PublisherType.hs
bsd-3-clause
3,641
0
11
536
751
414
337
68
1
import Test.DocTest main = doctest ["-isrc", "src/Data/BEncode/Reader.hs"]
matthewleon/bencode
tests/doctests.hs
bsd-3-clause
75
0
6
7
20
11
9
2
1
-- |Various types of hosts that Metasploit might interact -- with. Particularly, /attackable/ and /scannable/ hosts. {-# LANGUAGE EmptyDataDecls #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FunctionalDependencies #-} module MSF.Host where import MsgPack -- | A metasploit framework RPC server. data Server -- | A host that can have attacks launched against it. data Attackable -- | A host that can be scanned. data Scannable class ScanCxt t instance ScanCxt Scannable instance ScanCxt Attackable class ScanCxt t => AttackCxt t instance AttackCxt Attackable -- Individual Hosts ------------------------------------------------------------ -- | A host is just a name or an address. newtype Host t = Host { getHost :: String } deriving (Show,Eq,Ord) -- XXX dangerous, do not export castHost :: Host t -> Host t' castHost (Host n) = Host n attackableHost :: Host Scannable -> Host Attackable attackableHost = castHost instance ToObject (Host t) where toObject = toObject . getHost instance FromObject (Host t) where fromObject = fmap Host . fromObject -- Host Connections --------------------------------------------------------- -- | A connection is a host and a port. The MSF server itself is a connection. data Con t = Con { conHost :: Host t , conPort :: String } deriving (Show,Eq) -- XXX Don't export from a top-level api getCon :: Con t -> String getCon con | null (conPort con) = getHost (conHost con) ++ ":" ++ conPort con | otherwise = getHost (conHost con) -- Command Targets ---------------------------------------------------------- -- | One or more targets newtype Target t = Target { getTarget :: [TargetRange t] } deriving (Show) -- XXX dangerous, do not export castTarget :: Target t -> Target t' castTarget (Target ts) = Target (map castTargetRange ts) -- | A range of hosts. data TargetRange t = CIDR (Host t) Int | HostRange (Host t) (Host t) | SingleHost (Host t) deriving (Show) -- XXX dangerous, do not export castTargetRange :: TargetRange t -> TargetRange t' castTargetRange range = case range of CIDR h n -> CIDR (castHost h) n HostRange l r -> HostRange (castHost l) (castHost r) SingleHost h -> SingleHost (castHost h) class HostStage l r t | l r -> t instance HostStage Attackable Attackable Attackable instance HostStage Attackable Scannable Scannable instance HostStage Scannable Attackable Scannable instance HostStage Scannable Scannable Scannable -- | Target combination. This might need a better operator name at some point. (&) :: HostStage l r t => Target l -> Target r -> Target t l & r = Target (getTarget (castTarget l) ++ getTarget (castTarget r)) infixr 1 & -- | Construct a host range. to :: Host t -> Host t -> Target t lo `to` hi = Target [HostRange lo hi] -- | Construct a host range described by CIDR notation. cidr :: Host t -> Int -> Target t cidr h n = Target [CIDR h n] -- | Lift a single host into a target specification. single :: Host t -> Target t single h = Target [SingleHost h] -- | Convert a @Target@ into an application specific use. foldTarget :: (TargetRange t -> a -> a) -> a -> Target t -> a foldTarget fmt z = foldr fmt z . getTarget
GaloisInc/msf-haskell
src/MSF/Host.hs
bsd-3-clause
3,197
0
10
618
852
436
416
-1
-1
-- ChalkBoard Options -- October 2009 -- Kevin Matlage, Andy Gill module Graphics.ChalkBoard.Options where import Graphics.ChalkBoard.CBIR( BufferId ) import Data.Binary import Control.Monad data Options = NoFBO | DebugFrames | DebugAll -- ^ not supported (yet!) | DebugBoards [BufferId] -- ^ not supported (yet!) | BoardSize Int Int -- ^ default is 400x400. | FullScreen -- ^ not supported (yet!) | DebugCBIR | VerboseVideo deriving (Eq, Show) instance Binary Options where put (NoFBO) = put (0 :: Word8) put (DebugFrames) = put (1 :: Word8) put (DebugBoards buffs) = put (2 :: Word8) >> put buffs put (BoardSize w h) = put (3 :: Word8) >> put w >> put h put (FullScreen) = put (4 :: Word8) put (DebugCBIR) = put (5 :: Word8) put (VerboseVideo) = put (6 :: Word8) get = do tag <- getWord8 case tag of 0 -> return $ NoFBO 1 -> return $ DebugFrames 2 -> liftM DebugBoards get 3 -> liftM2 BoardSize get get 4 -> return $ FullScreen 5 -> return $ DebugCBIR 5 -> return $ VerboseVideo
andygill/chalkboard2
Graphics/ChalkBoard/Options.hs
bsd-3-clause
1,192
22
15
387
373
201
172
30
0
; ; HSP help manager—p HELPƒ\[ƒXƒtƒ@ƒCƒ‹ ; (æ“ª‚ªu;v‚̍s‚̓Rƒƒ“ƒg‚Æ‚µ‚ďˆ—‚³‚ê‚Ü‚·) ; %type Šg’£–½—ß %ver 3.4 %note hspcv.as‚ðƒCƒ“ƒNƒ‹[ƒh‚·‚邱‚ƁB %date 2009/08/01 %author onitama %dll hspcv %url http://hsp.tv/ %port Win %index cvreset HSPCV‚̏‰Šú‰» %group Šg’£‰æ–ʐ§Œä–½—ß %inst HSPCV‚ªŽ‚uCVƒoƒbƒtƒ@v‚ð‚·‚×‚Ä”jŠü‚µ‚āA‰Šúó‘Ô‚É–ß‚µ‚Ü‚·B HSPCV‚ÌŠJŽnAI—¹Žž‚ɂ͎©“®“I‚ɏ‰Šú‰»‚ªs‚È‚í‚ê‚Ü‚·B –¾Ž¦“I‚ɏ‰Šú‰»‚µ‚½‚¢Žž‚Écvreset–½—ß‚ðŽg—p‚µ‚Ä‚­‚¾‚³‚¢B %index cvsel ‘ΏÛCVƒoƒbƒtƒ@‚̐ݒè %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1 p1 : CVƒoƒbƒtƒ@ID %inst •W€‚Ì‘€ìæCVƒoƒbƒtƒ@ID‚ðÝ’肵‚Ü‚·B ƒpƒ‰ƒ[ƒ^[‚ŁACVƒoƒbƒtƒ@ID‚ðŽw’è‚·‚鎞‚ɏȗª‚µ‚½ê‡‚ɂ́A•W€‚Ì‘€ìæCVƒoƒbƒtƒ@ID‚ªŽg—p‚³‚ê‚Ü‚·B %index cvbuffer CVƒoƒbƒtƒ@‚ð‰Šú‰» %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3 p1(0) : CVƒoƒbƒtƒ@ID p2(640) : ‰¡‚̃sƒNƒZƒ‹ƒTƒCƒY p3(480) : c‚̃sƒNƒZƒ‹ƒTƒCƒY %inst Žw’肵‚½ƒTƒCƒY‚ÅCVƒoƒbƒtƒ@‚ð‰Šú‰»‚µ‚Ü‚·B ƒoƒbƒtƒ@‚ð‰Šú‰»‚·‚邱‚Ƃɂæ‚èAŠeŽí‰æ‘œˆ—‚ª‰Â”\‚ɂȂè‚Ü‚·B CVƒoƒbƒtƒ@‚́Aƒtƒ‹ƒJƒ‰[ƒ‚[ƒh(RGBŠe8bit)‚ŏ‰Šú‰»‚³‚ê‚Ü‚·B %href cvload %index cvresize ‰æ‘œ‚ÌƒŠƒTƒCƒY %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3,p4 p1(0) : ‰¡‚̃sƒNƒZƒ‹ƒTƒCƒY p2(0) : c‚̃sƒNƒZƒ‹ƒTƒCƒY p3 : CVƒoƒbƒtƒ@ID p4(1) : •âŠÔƒAƒ‹ƒSƒŠƒYƒ€ %inst CVƒoƒbƒtƒ@‚ð(p1,p2)‚ÅŽw’肵‚½ƒTƒCƒY‚ɕύX‚µ‚Ü‚·B p3‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B p4‚Å•âŠÔƒAƒ‹ƒSƒŠƒYƒ€‚ðŽw’肵‚Ü‚·B p4‚ÅŽw’è‚·‚é“à—e‚͈ȉº‚©‚ç1‚‘I‚Ô‚±‚Æ‚ª‚Å‚«‚Ü‚·B ^p CV_INTER_NN - ƒjƒAƒŒƒXƒgƒlƒCƒo[ CV_INTER_LINEAR - ƒoƒCƒŠƒjƒA(ƒfƒtƒHƒ‹ƒg) CV_INTER_AREA - ƒsƒNƒZƒ‹Žü•Ó‚ðƒŠƒTƒ“ƒvƒŠƒ“ƒO (ƒ‚ƒAƒŒ‚ð’ጸ‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·) CV_INTER_CUBIC - ƒoƒCƒLƒ…[ƒrƒbƒN ^p %index cvgetimg ‰æ‘œ‚̎擾 %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2 p1(0) : CVƒoƒbƒtƒ@ID p2(0) : Žæ“¾ƒ‚[ƒh %inst CVƒoƒbƒtƒ@‚Ì“à—e‚ðHSP‚̃EƒBƒ“ƒhƒEƒoƒbƒtƒ@‚É“]‘—‚µ‚Ü‚·B “]‘—æ‚ƂȂéHSP‚̃EƒBƒ“ƒhƒEƒoƒbƒtƒ@‚́Agsel–½—߂Ŏw’肳‚ê‚Ä‚¢‚錻Ý‚Ì‘€ìæƒEƒBƒ“ƒhƒEID‚ƂȂè‚Ü‚·B p1‚Å“]‘—Œ³‚ƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́AID0‚ªŽg—p‚³‚ê‚Ü‚·B p2‚ŁA“]‘—Žž‚Ì•û–@‚ðŽw’è‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B p2‚ª0‚̏ꍇ‚́AHSP‚̃EƒBƒ“ƒhƒEƒoƒbƒtƒ@ƒTƒCƒY‚Í‚»‚̂܂܂œ]‘—‚ðs‚È‚¢‚Ü‚·B p2‚É1‚ðŽw’肵‚½ê‡‚́ACVƒoƒbƒtƒ@‚Æ“¯‚¶ƒTƒCƒY‚ÉHSP‚̃EƒBƒ“ƒhƒEƒoƒbƒtƒ@ƒTƒCƒY‚ð•ύX‚µ‚½ã‚Å“]‘—‚ðs‚È‚¢‚Ü‚·B %href cvputimg %index cvputimg CVƒoƒbƒtƒ@‚ɏ‘‚«ž‚Ý %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1 p1 : CVƒoƒbƒtƒ@ID %inst HSP‚̃EƒBƒ“ƒhƒEƒoƒbƒtƒ@“à—e‚ðCVƒoƒbƒtƒ@‚É“]‘—‚µ‚Ü‚·B “]‘—Œ³‚ƂȂéHSP‚̃EƒBƒ“ƒhƒEƒoƒbƒtƒ@‚́Agsel–½—߂Ŏw’肳‚ê‚Ä‚¢‚錻Ý‚Ì‘€ìæƒEƒBƒ“ƒhƒEID‚ƂȂè‚Ü‚·B p1‚Å“]‘—æ‚ƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B %href cvgetimg %index cvload ‰æ‘œƒtƒ@ƒCƒ‹“ǂݍž‚Ý %group Šg’£‰æ–ʐ§Œä–½—ß %prm "filename",p1 "filename" : ‰æ‘œƒtƒ@ƒCƒ‹–¼ p1 : CVƒoƒbƒtƒ@ID %inst CVƒoƒbƒtƒ@‚ðŽw’肳‚ꂽ‰æ‘œƒtƒ@ƒCƒ‹‚Ì“à—e‚ŏ‰Šú‰»‚µ‚Ü‚·B p1‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B ‰æ‘œƒtƒ@ƒCƒ‹‚̃tƒH[ƒ}ƒbƒg‚̓tƒ@ƒCƒ‹Šg’£Žq‚É‚æ‚Á‚Ä”»’f‚³‚ê‚Ü‚·B Žg—p‚Å‚«‚éƒtƒH[ƒ}ƒbƒg‚ÆŠg’£Žq‚͈ȉº‚Ì’Ê‚è‚Å‚·B ^p Windows bitmaps - BMP, DIB JPEG files - JPEG, JPG, JPE Portable Network Graphics - PNG Portable image format - PBM, PGM, PPM Sun rasters - SR, RAS TIFF files - TIFF, TIF OpenEXR HDR images - EXR JPEG 2000 images - JP2 ^p ˆ—‚ª³í‚ɏI—¹‚µ‚½ê‡‚ɂ́AƒVƒXƒeƒ€•ϐ”stat‚ª0‚ɂȂè‚Ü‚·B ‰½‚ç‚©‚̃Gƒ‰[‚ª”­¶‚µ‚½ê‡‚ɂ́AƒVƒXƒeƒ€•ϐ”stat‚ª0ˆÈŠO‚Ì’l‚ƂȂè‚Ü‚·B #packA#epack“™‚ÅŽÀsƒtƒ@ƒCƒ‹‹y‚ÑDPMƒtƒ@ƒCƒ‹‚É–„‚ߍž‚܂ꂽƒtƒ@ƒCƒ‹‚͓ǂݍž‚Þ‚±‚Æ‚ª‚Å‚«‚Ü‚¹‚ñ‚̂ŒˆÓ‚µ‚Ä‚­‚¾‚³‚¢B %href cvsave %index cvsave ‰æ‘œƒtƒ@ƒCƒ‹‘‚«ž‚Ý %group Šg’£‰æ–ʐ§Œä–½—ß %prm "filename",p1,p2 "filename" : ‰æ‘œƒtƒ@ƒCƒ‹–¼ p1 : CVƒoƒbƒtƒ@ID p2 : ƒIƒvƒVƒ‡ƒ“’l %inst CVƒoƒbƒtƒ@‚Ì“à—e‚ðŽw’肳‚ꂽ‰æ‘œƒtƒ@ƒCƒ‹–¼‚ŕۑ¶‚µ‚Ü‚·B p1‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B ‰æ‘œƒtƒ@ƒCƒ‹‚̃tƒH[ƒ}ƒbƒg‚̓tƒ@ƒCƒ‹Šg’£Žq‚É‚æ‚Á‚Ä”»’f‚³‚ê‚Ü‚·B Žg—p‚Å‚«‚éƒtƒH[ƒ}ƒbƒg‚ÆŠg’£Žq‚͈ȉº‚Ì’Ê‚è‚Å‚·B ^p Windows bitmaps - BMP, DIB JPEG files - JPEG, JPG, JPE Portable Network Graphics - PNG Portable image format - PBM, PGM, PPM Sun rasters - SR, RAS TIFF files - TIFF, TIF OpenEXR HDR images - EXR JPEG 2000 images - JP2 ^p p2‚ÅŽw’è‚·‚éƒIƒvƒVƒ‡ƒ“’l‚́AƒtƒH[ƒ}ƒbƒg‚²‚Ƃ̐ݒè‚ðŽw’è‚·‚邽‚߂̂à‚̂ł·B Œ»Ý‚́AJPEGƒtƒH[ƒ}ƒbƒg•Û‘¶Žž‚Ì•iŽ¿(0`100)‚̂ݎw’è‰Â”\‚Å‚·B p2‚ÌŽw’è‚ðÈ—ª‚µ‚½ê‡‚́AJPEGƒtƒH[ƒ}ƒbƒg•Û‘¶Žž‚ɁA•iŽ¿95‚ªŽg—p‚³‚ê‚Ü‚·B ˆ—‚ª³í‚ɏI—¹‚µ‚½ê‡‚ɂ́AƒVƒXƒeƒ€•ϐ”stat‚ª0‚ɂȂè‚Ü‚·B ‰½‚ç‚©‚̃Gƒ‰[‚ª”­¶‚µ‚½ê‡‚ɂ́AƒVƒXƒeƒ€•ϐ”stat‚ª0ˆÈŠO‚Ì’l‚ƂȂè‚Ü‚·B %href cvload %index cvgetinfo CVƒoƒbƒtƒ@î•ñ‚ðŽæ“¾ %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3 p1 : CVƒoƒbƒtƒ@î•ñ‚ªŽæ“¾‚³‚ê‚é•ϐ” p2 : CVƒoƒbƒtƒ@ID p3 : CVƒoƒbƒtƒ@î•ñID %inst CVƒoƒbƒtƒ@‚ÉŠÖ‚·‚éî•ñ‚ðŽæ“¾‚µ‚Äp1‚̕ϐ”‚É‘ã“ü‚µ‚Ü‚·B p2‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B p3‚Ŏ擾‚·‚éî•ñ‚ÌŽí—Þ‚ðŽw’è‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B p3‚ÉŽw’è‚Å‚«‚éƒ}ƒNƒ‚͈ȉº‚Ì’Ê‚è‚Å‚·B ^p ƒ}ƒNƒ “à—e ------------------------------------------- CVOBJ_INFO_SIZEX ‰¡•ûŒüƒTƒCƒY CVOBJ_INFO_SIZEY c•ûŒüƒTƒCƒY CVOBJ_INFO_CHANNEL ƒ`ƒƒƒ“ƒlƒ‹” CVOBJ_INFO_BIT ƒ`ƒƒƒ“ƒlƒ‹‚ ‚½‚è‚̃rƒbƒg” ^p %href cvbuffer cvload %index cvsmooth ‰æ‘œ‚̃Xƒ€[ƒWƒ“ƒO %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3,p4,p5 p1 : ƒXƒ€[ƒWƒ“ƒO‚̃^ƒCƒv p2 : param1 p3 : param2 p4 : param3 p5 : CVƒoƒbƒtƒ@ID %inst CVƒoƒbƒtƒ@‚ɃXƒ€[ƒWƒ“ƒO‚ð“K—p‚µ‚Ü‚·B p5‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B p1‚ÅŽw’è‚·‚邱‚Ƃ̂ł«‚éƒ}ƒNƒ‚͈ȉº‚Ì’Ê‚è‚Å‚·B CV_BLUR_NO_SCALE (param1~param2‚̗̈æ‚ŃsƒNƒZƒ‹’l‚ð‘«‚µ‡‚킹‚é) CV_BLUR (param1~param2‚̗̈æ‚ŃsƒNƒZƒ‹’l‚ð‘«‚µ‡‚킹‚½ŒãA 1/(param1*param2)‚ŃXƒP[ƒŠƒ“ƒO‚·‚é) CV_GAUSSIAN (param1~param2ƒKƒEƒVƒAƒ“ƒtƒBƒ‹ƒ^) CV_MEDIAN (param1~param2ƒƒfƒBƒAƒ“ƒtƒBƒ‹ƒ^) CV_BILATERAL (3~3ƒoƒCƒ‰ƒeƒ‰ƒ‹ƒtƒBƒ‹ƒ^(param1=F•ªŽU, param2=‹óŠÔ•ªŽU)) ^p http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html ^p uparam1~param2v‚̃pƒ‰ƒ[ƒ^[‚́A1ˆÈã‚̊‚ðŽw’è‚·‚é•K—v‚ª‚ ‚è‚Ü‚·B %index cvthreshold ‰æ‘œ‚ð臒l‚Ŏ擾 %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3,p4 p1 : ‚Q’l‰»ƒ^ƒCƒv p2 : 臒l(ŽÀ”) p3 : “ñ’l‰»Œã‚̉æ‘f’l(ŽÀ”) p4 : CVƒoƒbƒtƒ@ID %inst CVƒoƒbƒtƒ@‚ɑ΂µ‚Ä臒l‚ð‚à‚Æ‚É‚Q’l‰»‚ðs‚È‚¢‚Ü‚·B p4‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B p1‚ÅŽw’è‚·‚邱‚Ƃ̂ł«‚éƒ}ƒNƒ‚͈ȉº‚Ì’Ê‚è‚Å‚·B ^p CV_THRESH_BINARY : val = (val > thresh ? MAX:0) CV_THRESH_BINARY_INV : val = (val > thresh ? 0:MAX) CV_THRESH_TRUNC : val = (val > thresh ? thresh:val) CV_THRESH_TOZERO : val = (val > thresh ? val:0) CV_THRESH_TOZERO_INV : val = (val > thresh ? 0:val) ^p %index cvrotate ‰æ‘œ‚̉ñ“] %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3,p4,p5,p6 p1(0) : Šp“x(ŽÀ”) p2(1) : ƒXƒP[ƒ‹(ŽÀ”) p3(0) : ’†SÀ•W‚ÌXƒIƒtƒZƒbƒg(ŽÀ”) p4(0) : ’†SÀ•W‚ÌYƒIƒtƒZƒbƒg(ŽÀ”) p5 : •âŠÔƒAƒ‹ƒSƒŠƒYƒ€ p6 : CVƒoƒbƒtƒ@ID %inst CVƒoƒbƒtƒ@‘S‘Ì‚ð‰ñ“]‚³‚¹‚Ü‚·B p1‚ÅŠp“x(360“x‚ňêŽü)‚ðAp2‚ŃXƒP[ƒ‹‚ðÝ’肵‚Ü‚·B (p3,p4)‚Å’†S‚̃IƒtƒZƒbƒg‚ðŽw’è‚·‚邱‚Æ‚ª‚Ä‚«‚Ü‚·B p5‚ŁA‰ñ“]Žž‚Ì•âŠÔƒAƒ‹ƒSƒŠƒYƒ€‚ðŽw’肵‚Ü‚·B p5‚ÅŽw’è‚·‚é“à—e‚͈ȉº‚©‚ç1‚‘I‚Ô‚±‚Æ‚ª‚Å‚«‚Ü‚·B ^p CV_INTER_NN - ƒjƒAƒŒƒXƒgƒlƒCƒo[ CV_INTER_LINEAR - ƒoƒCƒŠƒjƒA(ƒfƒtƒHƒ‹ƒg) CV_INTER_AREA - ƒsƒNƒZƒ‹Žü•Ó‚ðƒŠƒTƒ“ƒvƒŠƒ“ƒO (ƒ‚ƒAƒŒ‚ð’ጸ‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·) CV_INTER_CUBIC - ƒoƒCƒLƒ…[ƒrƒbƒN ^p ‚Ü‚½Ap5‚É“¯ŽžŽw’è‚Å‚«‚éƒIƒvƒVƒ‡ƒ“‚ª—pˆÓ‚³‚ê‚Ä‚¢‚Ü‚·B ^p CV_WARP_FILL_OUTLIERS - ŠO•”ƒsƒNƒZƒ‹‚ð–„‚ß‚é CV_WARP_INVERSE_MAP - ‰ñ“]‚ð‹ts—ñ‚ōs‚È‚¤ ^p ƒfƒtƒHƒ‹ƒg‚ł́ACV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS‚ªŽw’肳‚ê‚Ä‚¢‚Ü‚·B p6‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B %index cvarea ƒRƒs[Œ³—̈æ‚ÌŽw’è %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3,p4 p1(0) : ƒRƒs[Œ³ XÀ•W p2(0) : ƒRƒs[Œ³ YÀ•W p3(0) : ƒRƒs[—̈æ XƒTƒCƒY p4(0) : ƒRƒs[—̈æ YƒTƒCƒY %inst cvcopy–½—߂ʼn摜‚̃Rƒs[‚ðs‚È‚¤Û‚̃Rƒs[Œ³—̈æ‚ðŽw’肵‚Ü‚·B ƒpƒ‰ƒ[ƒ^[‚ª‚·‚ׂÄ0‚̏ꍇ‚âA‚·‚ׂďȗª‚µ‚Äcvarea–½—ß‚ðŽÀs‚µ‚½ê‡‚́ACVƒoƒbƒtƒ@‘S‘Ì‚ª‘ΏۂɂȂè‚Ü‚·B %href cvcopy %index cvcopy ‰æ‘œ‚̃Rƒs[ %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3,p4,p5 p1(0) : ƒRƒs[Œ³CVƒoƒbƒtƒ@ID p2(0) : ƒRƒs[æ XÀ•W p3(0) : ƒRƒs[æ YÀ•W p4 : ƒRƒs[æCVƒoƒbƒtƒ@ID p5(0) : ‰‰ŽZƒIƒvƒVƒ‡ƒ“ %inst CVƒoƒbƒtƒ@‚Ì“à—e‚ð•Ê‚ÈCVƒoƒbƒtƒ@‚ɃRƒs[‚µ‚Ü‚·B p1‚ÅŽw’肳‚ꂽCVƒoƒbƒtƒ@ID‚ªƒRƒs[Œ³‚Æ‚µ‚ÄŽg—p‚³‚ê‚Ü‚·B ƒoƒbƒtƒ@‚̈ꕔ‚ðƒRƒs[‚·‚éê‡‚ɂ́Acvarea–½—߂ňʒu‚âƒTƒCƒY‚ð‚ ‚ç‚©‚¶‚ߐݒ肵‚Ä‚¨‚­•K—v‚ª‚ ‚è‚Ü‚·B p5‚̉‰ŽZƒIƒvƒVƒ‡ƒ“‚É‚æ‚èAƒRƒs[Žž‚É‚¢‚­‚‚©‚̉‰ŽZ‚ðs‚È‚¤‚±‚Æ‚ª‰Â”\‚Å‚·Bp5‚ÉŽw’è‚Å‚«‚éƒ}ƒNƒ‚͈ȉº‚Ì’Ê‚è‚Å‚·B ^p CVCOPY_SET (ã‘‚«ƒRƒs[) CVCOPY_ADD (‰ÁŽZ) CVCOPY_SUB (Œ¸ŽZ) CVCOPY_MUL (æŽZ) CVCOPY_DIF (·•ª) CVCOPY_AND (˜_—Ï) ^p p4‚ŃRƒs[æ‚ƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B CVƒoƒbƒtƒ@‚̐Fƒ‚[ƒh‚́AƒRƒs[Œ³‚ƃRƒs[æ‚ō‡‚킹‚Ä‚¨‚­•K—v‚ª‚ ‚è‚Ü‚·B ƒOƒŒƒCƒXƒP[ƒ‹(”’•)‰æ–ʂƃtƒ‹ƒJƒ‰[‰æ–Ê‚ð¬Ý‚µ‚ăRƒs[‚·‚邱‚Ƃ͂ł«‚Ü‚¹‚ñB %href cvarea %index cvxors ‰æ‘œ‚ÌXOR‰‰ŽZ %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3,p4 p1(255) : XOR‰‰ŽZ‚ÅŽg—p‚·‚éR’l p2(255) : XOR‰‰ŽZ‚ÅŽg—p‚·‚éG’l p3(255) : XOR‰‰ŽZ‚ÅŽg—p‚·‚éB’l p4 : ƒRƒs[æCVƒoƒbƒtƒ@ID %inst CVƒoƒbƒtƒ@‚Ì“à—e‚ɑ΂µ‚ÄXOR‰‰ŽZ‚ðs‚È‚¢‚Ü‚·B p1`p3‚܂łŁARGB’l‚ɑ΂·‚鉉ŽZ’l(0`255)‚ðŽw’肵‚Ü‚·B p4‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B %href cvcopy %index cvflip ‰æ‘œ‚Ì”½“] %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2 p1(0) : ”½“]‚̃‚[ƒh p2 : ƒRƒs[æCVƒoƒbƒtƒ@ID %inst CVƒoƒbƒtƒ@‚Ì“à—e‚𔽓]‚³‚¹‚Ü‚·B p1‚Å”½“]‚̃‚[ƒh‚ðŽw’è‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B p1‚ª0‚̏ꍇ‚́Aã‰º”½“]‚ɂȂè‚Ü‚·B p1‚ª1ˆÈã‚̏ꍇ‚́A¶‰E”½“]‚ɂȂè‚Ü‚·B p1‚ªƒ}ƒCƒiƒX’l‚̏ꍇ‚́Aã‰º¶‰E‚Æ‚à‚É”½“]‚³‚ê‚Ü‚·B p2‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B %index cvloadxml XMLƒtƒ@ƒCƒ‹‚̓ǂݍž‚Ý %group Šg’£‰æ–ʐ§Œä–½—ß %prm "filename" "filename" : “ǂݍž‚ÞXMLƒtƒ@ƒCƒ‹–¼ %inst "filename"‚ÅŽw’肳‚ꂽƒtƒ@ƒCƒ‹‚ðXMLƒtƒ@ƒCƒ‹‚Æ‚µ‚ēǂݍž‚݂܂·B XMLƒtƒ@ƒCƒ‹‚́A‰æ‘œ‚ÌŠç”Fޝ“™‚Å•K—v‚ȏꍇ‚É‚ ‚ç‚©‚¶‚ߓǂݍž‚ñ‚Å‚¨‚­•K—v‚ª‚ ‚è‚Ü‚·B ˆ—‚ª³í‚ɏI—¹‚µ‚½ê‡‚ɂ́AƒVƒXƒeƒ€•ϐ”stat‚ª0‚ɂȂè‚Ü‚·B ‰½‚ç‚©‚̃Gƒ‰[‚ª”­¶‚µ‚½ê‡‚ɂ́AƒVƒXƒeƒ€•ϐ”stat‚ª0ˆÈŠO‚Ì’l‚ƂȂè‚Ü‚·B #packA#epack“™‚ÅŽÀsƒtƒ@ƒCƒ‹‹y‚ÑDPMƒtƒ@ƒCƒ‹‚É–„‚ߍž‚܂ꂽƒtƒ@ƒCƒ‹‚͓ǂݍž‚Þ‚±‚Æ‚ª‚Å‚«‚Ü‚¹‚ñ‚̂ŒˆÓ‚µ‚Ä‚­‚¾‚³‚¢B %href cvfacedetect %index cvfacedetect ‰æ‘œ‚ÌŠç”Fޝ %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2 p1 : CVƒoƒbƒtƒ@ID p2(1) : ƒXƒP[ƒ‹’l(ŽÀ”) %inst CVƒoƒbƒtƒ@‚̉摜‚©‚ç“Á’è‚̃pƒ^[ƒ“‚ð”Fޝ‚µ‚Ü‚·B ƒpƒ^[ƒ“‚̃pƒ‰ƒ[ƒ^[‚ðŽ‚Âxmlƒtƒ@ƒCƒ‹‚ðA‚ ‚ç‚©‚¶‚ßcvloadxml–½—߂œǂݍž‚ñ‚Å‚¨‚­•K—v‚ª‚ ‚è‚Ü‚·B p1‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B p2‚ŏˆ—Žž‚̃XƒP[ƒ‹‚ðÝ’è‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B ‚±‚±‚Å1‚æ‚è‘å‚«‚¢’l‚ðŽw’è‚·‚邯Aˆ—Žž‚Ƀoƒbƒtƒ@ƒTƒCƒY‚ðk¬‚µ‚ďˆ—‚³‚ê‚邿‚¤‚ɂȂè‚Ü‚·B‘å‚«‚ȉ摜“™‚ÅŽžŠÔ‚ª ‚©‚©‚éê‡‚ȂǂɎw’è‚·‚邯‚¢‚¢‚Å‚µ‚傤B ŽÀsŒã‚ɁAƒVƒXƒeƒ€•ϐ”stat‚É”Fޝ‚³‚ꂽ”‚ª•Ô‚³‚ê‚Ü‚·B stat‚ª0‚̏ꍇ‚́A‚Ü‚Á‚½‚­”Fޝ‚³‚ê‚Ä‚¢‚È‚¢‚±‚Æ‚ðŽ¦‚µ‚Ü‚·B stat‚ª1ˆÈã‚̏ꍇ‚́Acvgetface–½—߂ɂæ‚Á‚Ä”Fޝ‚³‚ꂽ—̈æ‚ðŽæ“¾‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B %href cvgetface cvloadxml %index cvgetface ”Fޝ‚³‚ꂽÀ•W‚̎擾 %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3,p4 p1 : ”Fޝ‚³‚ꂽXÀ•W‚ª‘ã“ü‚³‚ê‚é•ϐ” p2 : ”Fޝ‚³‚ꂽYÀ•W‚ª‘ã“ü‚³‚ê‚é•ϐ” p3 : ”Fޝ‚³‚ꂽXƒTƒCƒY‚ª‘ã“ü‚³‚ê‚é•ϐ” p4 : ”Fޝ‚³‚ꂽYƒTƒCƒY‚ª‘ã“ü‚³‚ê‚é•ϐ” %inst cvfacedetect–½—߂ɂæ‚Á‚Ä”Fޝ‚³‚ꂽ—̈æ‚ðŽæ“¾‚µ‚Ü‚·B p1‚©‚çp4‚܂ł̕ϐ”‚ɁAÀ•W’l‚ª®”‚Å‘ã“ü‚³‚ê‚Ü‚·B cvfacedetect–½—߂ɂæ‚Á‚Ä”Fޝ‚³‚ꂽŒÂ”‚¾‚¯AŒJ‚è•Ô‚µ‚ė̈æ‚ðŽæ“¾‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B ³í‚Ɏ擾‚Å‚«‚½ê‡‚ɂ́AŽÀsŒã‚ɃVƒXƒeƒ€•ϐ”stat‚ª0‚ɂȂè‚Ü‚·B Žæ“¾‚Å‚«‚éƒf[ƒ^‚ª‚È‚¢ê‡‚ɂ́AƒVƒXƒeƒ€•ϐ”stat‚Í1‚ɂȂè‚Ü‚·B %href cvfacedetect %index cvmatch ‰æ‘œ‚̃}ƒbƒ`ƒ“ƒOŒŸ¸ %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2,p3,p4,p5 p1 : ”Fޝ‚³‚ꂽXÀ•W‚ª‘ã“ü‚³‚ê‚é•ϐ” p2 : ”Fޝ‚³‚ꂽYÀ•W‚ª‘ã“ü‚³‚ê‚é•ϐ” p3 : ƒ}ƒbƒ`ƒ“ƒO‚̃^ƒCƒv p4 : ƒ}ƒbƒ`ƒ“ƒOŒ³‚ÌCVƒoƒbƒtƒ@ID p5 : ƒ}ƒbƒ`ƒ“ƒOæ‚ÌCVƒoƒbƒtƒ@ID %inst ƒ}ƒbƒ`ƒ“ƒOæ‚ÌCVƒoƒbƒtƒ@‚Ì’†‚©‚çAƒ}ƒbƒ`ƒ“ƒOŒ³‚ÌCVƒoƒbƒtƒ@‚ɍłà‹ß‚¢—̈æ‚ð’T‚µo‚µ‚ÄŒ‹‰Ê‚ð•Ô‚µ‚Ü‚·B ŽÀsŒãA(p1,p2)‚ÉŽw’肵‚½•ϐ”‚ÖŒ‹‰Ê‚ƂȂéÀ•W‚ð‘ã“ü‚µ‚Ü‚·B p3‚Ń}ƒbƒ`ƒ“ƒO‚ÅŽg—p‚·‚é•]‰¿•û–@‚̃^ƒCƒv‚ðŽw’肵‚Ü‚·B p3‚ÅŽw’è‚·‚邱‚Ƃ̂ł«‚éƒ}ƒNƒ‚͈ȉº‚Ì’Ê‚è‚Å‚·B ^p CV_TM_SQDIFF R(x,y)=sumx',y'[T(x',y')-I(x+x',y+y')]^2 CV_TM_SQDIFF_NORMED R(x,y)=sumx',y'[T(x',y')-I(x+x',y+y')]^2/sqrt[sumx',y'T(x',y')^2Esumx',y'I(x+x',y+y')^2] CV_TM_CCORR R(x,y)=sumx',y'[T(x',y')EI(x+x',y+y')] CV_TM_CCORR_NORMED R(x,y)=sumx',y'[T(x',y')EI(x+x',y+y')]/sqrt[sumx',y'T(x',y')^2Esumx',y'I(x+x',y+y')^2] CV_TM_CCOEFF R(x,y)=sumx',y'[T'(x',y')EI'(x+x',y+y')], where T'(x',y')=T(x',y') - 1/(wEh)Esumx",y"T(x",y") I'(x+x',y+y')=I(x+x',y+y') - 1/(wEh)Esumx",y"I(x+x",y+y") CV_TM_CCOEFF_NORMED R(x,y)=sumx',y'[T'(x',y')EI'(x+x',y+y')]/sqrt[sumx',y'T'(x',y')^2Esumx',y'I'(x+x',y+y')^2] ^p p5‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B cvmatch–½—߂́A‚ ‚­‚܂łàÅ‚à‹ß‚¢—̈æ‚ðŒŸõ‚·‚邾‚¯‚ŁAŠ®‘S‚É“¯‚¶‚Å‚ ‚邱‚Æ‚ð•ۏႷ‚é‚à‚̂ł͂ ‚è‚Ü‚¹‚ñB %index cvconvert Fƒ‚[ƒh‚̕ϊ· %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2 p1(0) : •ÏŠ·ƒ‚[ƒh p2 : CVƒoƒbƒtƒ@ID %inst CVƒoƒbƒtƒ@‚ðp1‚ÅŽw’肳‚ꂽFƒ‚[ƒh‚ɕϊ·‚µ‚Ü‚·B p1‚ª0‚̏ꍇ‚́Aƒtƒ‹ƒJƒ‰[‰æ–Ê‚ðƒOƒŒƒCƒXƒP[ƒ‹(”’•)‰æ–ʂɁB p1‚ª1‚̏ꍇ‚́AƒOƒŒƒCƒXƒP[ƒ‹(”’•)‰æ–Ê‚ðƒtƒ‹ƒJƒ‰[‰æ–ʂɁA‚»‚ꂼ‚ê•ÏŠ·‚µ‚Ü‚·B p2‚őΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B %index cvcapture ƒJƒƒ‰ƒLƒƒƒvƒ`ƒƒ‚ÌŠJŽn %group Šg’£‰æ–ʐ§Œä–½—ß %prm p1,p2 p1(0) : ƒJƒƒ‰ID p2 : CVƒoƒbƒtƒ@ID %inst ƒLƒƒƒvƒ`ƒƒƒfƒoƒCƒX‚©‚ç‚Ì“ü—Í‚ðŠJŽn‚µ‚Ü‚·B p1‚ŁAƒJƒƒ‰‚ð“Á’è‚·‚邽‚߂̃Jƒƒ‰ID‚ðŽw’肵‚Ü‚·B p1‚ÅŽw’è‚Å‚«‚é’l‚͈ȉº‚Ì’Ê‚è‚Å‚·B •¡”‚̃fƒoƒCƒX‚ªÚ‘±‚³‚ê‚Ä‚¢‚éê‡‚́A1‚’l‚ð‰ÁŽZ‚·‚邱‚ƂœÁ’è‚·‚邱‚Æ‚ª‰Â”\‚Å‚·B ^p ƒ}ƒNƒ ’l “à—e ------------------------------------------------- CV_CAP_ANY 0 —˜—p‰Â”\‚ȃfƒoƒCƒX‚·‚×‚Ä CV_CAP_MIL 100 Matrox Imaging Library CV_CAP_VFW 200 Video for Windows CV_CAP_IEEE1394 300 IEEE1394(Œ»ƒo[ƒWƒ‡ƒ“‚ł͖¢‘Ήž‚Å‚·) ^p p2‚ŃLƒƒƒvƒ`ƒƒ‚µ‚½‰æ‘œ‚ð•Û‘¶‚·‚é‘ΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B ƒJƒƒ‰ƒLƒƒƒvƒ`ƒƒ‚ÌŠJŽnŒã‚́Acvgetcapture–½—߂ɂæ‚Á‚ătƒŒ[ƒ€‚²‚Ƃ̉摜‚ðŽæ“¾‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B ‚Ü‚½A•s—v‚ɂȂÁ‚½ê‡‚ɂ͕K‚¸cvendcapture–½—߂ŃLƒƒƒvƒ`ƒƒ‚ðI—¹‚³‚¹‚é•K—v‚ª‚ ‚è‚Ü‚·B %href cvgetcapture cvendcapture %index cvgetcapture ƒLƒƒƒvƒ`ƒƒ‰æ‘œ‚̎擾 %group Šg’£‰æ–ʐ§Œä–½—ß %inst cvcapture–½—߂ɂæ‚Á‚ÄŠJŽn‚³‚ꂽƒLƒƒƒvƒ`ƒƒ‚̃tƒŒ[ƒ€‰æ‘œ‚ðŽæ“¾‚µ‚Ü‚·B Žæ“¾‚³‚ê‚éCVƒoƒbƒtƒ@‚́Acvcapture–½—߂Őݒ肳‚ꂽID‚ɂȂè‚Ü‚·B %href cvcapture %index cvendcapture ƒJƒƒ‰ƒLƒƒƒvƒ`ƒƒ‚̏I—¹ %group Šg’£‰æ–ʐ§Œä–½—ß %inst cvcapture–½—߂ɂæ‚Á‚ÄŠJŽn‚³‚ꂽƒLƒƒƒvƒ`ƒƒ‚ðI—¹‚µ‚Ü‚·B %href cvcapture %index cvopenavi aviƒtƒ@ƒCƒ‹Žæ“¾‚ÌŠJŽn %group Šg’£‰æ–ʐ§Œä–½—ß %prm "filename",p1 "filename" : avi“®‰æƒtƒ@ƒCƒ‹–¼ p1 : CVƒoƒbƒtƒ@ID %inst avi“®‰æƒtƒ@ƒCƒ‹‚©‚ç‚Ì“ü—Í‚ðŠJŽn‚µ‚Ü‚·B Žw’肳‚ꂽƒtƒ@ƒCƒ‹“à‚̃tƒŒ[ƒ€‚ðŽæ“¾‚·‚邱‚Æ‚ª‚Å‚«‚邿‚¤‚ɂȂè‚Ü‚·B p1‚ŃLƒƒƒvƒ`ƒƒ‚µ‚½‰æ‘œ‚ð•Û‘¶‚·‚é‘ΏۂƂȂéCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B aviƒtƒ@ƒCƒ‹Žæ“¾‚ÌŠJŽnŒã‚́Acvgetavi–½—߂ɂæ‚Á‚ătƒŒ[ƒ€‚²‚Ƃ̉摜‚ðŽæ“¾‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B ‚Ü‚½A•s—v‚ɂȂÁ‚½ê‡‚ɂ͕K‚¸cvcloseavi–½—ß‚Åaviƒtƒ@ƒCƒ‹Žæ“¾‚ðI—¹‚³‚¹‚é•K—v‚ª‚ ‚è‚Ü‚·B cvopenavi–½—߂́A‚ ‚­‚܂łàaviƒtƒ@ƒCƒ‹‚Ì“à—e‚ðŠÈˆÕ“I‚ÉŽæ‚èo‚·‚½‚߂̋@”\‚ŁA³í‚È“®‰æÄ¶‚ðs‚È‚¤‚½‚߂̂à‚̂ł͂ ‚è‚Ü‚¹‚ñB‚ ‚­‚܂łàAƒtƒŒ[ƒ€‚ðŽæ‚èo‚µ‚ďˆ—‚ðs‚È‚¤‚½‚߂̕⏕‹@”\‚¾‚Æ‚¨l‚¦‚­‚¾‚³‚¢B ‚Ü‚½Acvopenavi–½—ß‚ªˆµ‚¤‚±‚Ƃ̂ł«‚éaviƒtƒ@ƒCƒ‹‚́AŒÃ‚¢Œ`Ž®‚ÌaviƒtƒH[ƒ}ƒbƒg‚ÉŒÀ‚ç‚ê‚Ä‚¨‚èA‚·‚ׂĂÌaviƒtƒ@ƒCƒ‹‚ðŠJ‚­‚±‚Æ‚ª‚Å‚«‚é‚킯‚ł͂ ‚è‚Ü‚¹‚ñB %href cvgetavi cvcloseavi %index cvgetavi aviƒtƒ@ƒCƒ‹‰æ‘œ‚̎擾 %group Šg’£‰æ–ʐ§Œä–½—ß %inst cvopenavi–½—߂ɂæ‚Á‚ÄŠJŽn‚³‚ꂽaviƒtƒ@ƒCƒ‹‚̃tƒŒ[ƒ€‰æ‘œ‚ðŽæ“¾‚µ‚Ü‚·B Žæ“¾‚³‚ê‚éCVƒoƒbƒtƒ@‚́Acvcapture–½—߂Őݒ肳‚ꂽID‚ɂȂè‚Ü‚·B %href cvopenavi %index cvcloseavi aviƒtƒ@ƒCƒ‹Žæ“¾‚̏I—¹ %group Šg’£‰æ–ʐ§Œä–½—ß %prm %inst cvopenavi–½—߂ɂæ‚Á‚ÄŠJŽn‚³‚ꂽaviƒtƒ@ƒCƒ‹Žæ“¾‚ðI—¹‚µ‚Ü‚·B %href cvopenavi %index cvmakeavi aviƒtƒ@ƒCƒ‹o—͂̊JŽn %group Šg’£‰æ–ʐ§Œä–½—ß %prm "filename",p1,p2,p3 "filename" : o—Í‚·‚éavi“®‰æƒtƒ@ƒCƒ‹–¼ p1(-1) : 32bit CodecƒR[ƒh p2(29.97) : ŽÀ”‚É‚æ‚éƒtƒŒ[ƒ€ƒŒ[ƒg(fps) p3 : CVƒoƒbƒtƒ@ID %inst avi“®‰æƒtƒ@ƒCƒ‹‚ւ̏o—Í‚ðŠJŽn‚µ‚Ü‚·B Žw’肳‚ꂽƒtƒ@ƒCƒ‹–¼‚Åaviƒtƒ@ƒCƒ‹‚ðì¬‚µ‚Ü‚·B p1‚ŃR[ƒfƒbƒN‚ªŽ‚Â32bit‚̃R[ƒh(FOURCC)‚ðŽw’肵‚Ü‚·B p1‚É-1‚ðŽw’肵‚½ê‡‚́AƒR[ƒfƒbƒN‚ð‘I‘ð‚·‚éƒ_ƒCƒAƒƒO‚ªŠJ‚«‚Ü‚·B p2‚ÅŽÀ”‚É‚æ‚éƒtƒŒ[ƒ€ƒŒ[ƒg(fps)‚ðŽw’肵‚Ü‚·B p2‚ÌŽw’肪È—ª‚³‚ꂽê‡‚ɂ́A29.97fps‚ƂȂè‚Ü‚·B p3‚ŏo—͉摜‚ð•ÛŽ‚·‚éCVƒoƒbƒtƒ@ID‚ðŽw’肵‚Ü‚·B È—ª‚³‚ꂽê‡‚́Acvsel–½—߂Őݒ肳‚ꂽID‚ªŽg—p‚³‚ê‚Ü‚·B o—͂̊JŽnŒã‚́Acvputavi–½—߂ɂæ‚Á‚ătƒŒ[ƒ€‚²‚Ƃ̉摜‚ð“o˜^‚µ‚āAÅŒã‚Écvendavi–½—ß‚ðŒÄ‚яo‚·•K—v‚ª‚ ‚è‚Ü‚·B %href cvputavi cvendavi %index cvputavi aviƒtƒ@ƒCƒ‹‚ɉ摜‚ðo—Í %group Šg’£‰æ–ʐ§Œä–½—ß %inst cvmakeavi–½—߂ɂæ‚Á‚ÄŠJŽn‚³‚ꂽaviƒtƒ@ƒCƒ‹‚ɁAƒtƒŒ[ƒ€‰æ‘œ‚ð’ljÁ‚µ‚Ü‚·B ŽQÆ‚³‚ê‚éCVƒoƒbƒtƒ@‚́Acvmakeavi–½—߂Őݒ肳‚ꂽID‚ɂȂè‚Ü‚·B %href cvmakeavi %index cvendavi aviƒtƒ@ƒCƒ‹o—͂̏I—¹ %group Šg’£‰æ–ʐ§Œä–½—ß %inst cvmakeavi–½—߂ɂæ‚Á‚ÄŠJŽn‚³‚ꂽaviƒtƒ@ƒCƒ‹o—Í‚ðI—¹‚µ‚Ü‚·B %href cvmakeavi %index cvj2opt JPEG-2000•Û‘¶ƒIƒvƒVƒ‡ƒ“Ý’è %group Šg’£‰æ–ʐ§Œä–½—ß %prm "format","option" "format" : ƒtƒH[ƒ}ƒbƒg•¶Žš—ñ "option" : ƒIƒvƒVƒ‡ƒ“•¶Žš—ñ %inst cvsave–½—ß‚ÅJPEG-2000Œ`Ž®(.jp2)‚ðŽw’肵‚½Û‚̏ڍאݒè‚ðs‚È‚¢‚Ü‚·B ƒtƒH[ƒ}ƒbƒg•¶Žš—ñ‚ɂ́AˆÈ‰º‚Ì‚¢‚¸‚ê‚©‚ðŽw’è‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B (JPEGˆÈŠO‚̃tƒH[ƒ}ƒbƒg‚ðŽw’肵‚½ê‡‚Å‚àAŠg’£Žq‚Íjp2‚̂܂܂ɂȂé‚̂ŒˆÓ‚µ‚Ä‚­‚¾‚³‚¢) ^p ƒtƒH[ƒ}ƒbƒg•¶Žš—ñ Œ`Ž® ---------------------------------------- mif My Image Format pnm Portable Graymap/Pixmap bmp Microsoft Bitmap ras Sun Rasterfile jp2 JPEG2000 JP2 File Format Syntax jpc JPEG2000 Code Stream Syntax jpg JPEG pgx JPEG2000 VM Format ^p ƒIƒvƒVƒ‡ƒ“•¶Žš—ñ‚É‚æ‚èA•t‰ÁÝ’è‚ðs‚È‚¤‚±‚Æ‚ª‚Å‚«‚Ü‚·B ^p —á: cvj2opt "jp2","rate=0.1" cvsave "test2000.jp2" ^p ƒIƒvƒVƒ‡ƒ“•¶Žš—ñ‚́AƒtƒH[ƒ}ƒbƒg‚²‚Ƃɐݒè•û–@‚ªˆÙ‚È‚è‚Ü‚·B Ú‚µ‚­‚́Ajasperƒ‰ƒCƒuƒ‰ƒŠ‚Ɋ܂܂ê‚éAƒRƒ}ƒ“ƒhƒ‰ƒCƒ“ƒc[ƒ‹ jasper‚̃IƒvƒVƒ‡ƒ“‚ðŽQÆ‚µ‚Ä‚­‚¾‚³‚¢B ^p http://www.ece.uvic.ca/~mdadams/jasper/ ^p %href cvsave
zakki/openhsp
package/hsphelp/hspcv.hs
bsd-3-clause
19,075
8,088
28
2,145
18,836
10,053
8,783
-1
-1
{-# LANGUAGE TupleSections, RecordWildCards, CPP #-} module Network.HPACK.Table ( -- * dynamic table DynamicTable , newDynamicTableForEncoding , newDynamicTableForDecoding , renewDynamicTable , printDynamicTable , isDynamicTableEmpty -- * Insertion , insertEntry -- * Header to index , HeaderCache(..) , lookupTable -- * Entry , module Network.HPACK.Table.Entry -- * Which tables , WhichTable(..) , which ) where #if __GLASGOW_HASKELL__ < 709 import Control.Applicative ((<$>)) #endif import Control.Exception (throwIO) import Network.HPACK.Table.Dynamic import Network.HPACK.Table.Entry import qualified Network.HPACK.Table.DoubleHashMap as DHM import Network.HPACK.Table.Static import Network.HPACK.Types ---------------------------------------------------------------- -- | Which table does `Index` refer to? data WhichTable = InDynamicTable | InStaticTable deriving (Eq,Show) -- | Is header key-value stored in the tables? data HeaderCache = None | KeyOnly WhichTable Index | KeyValue WhichTable Index deriving Show ---------------------------------------------------------------- -- | Resolving an index from a header. -- Static table is prefer to dynamic table. lookupTable :: Header -> DynamicTable -> HeaderCache lookupTable h hdrtbl = case reverseIndex hdrtbl of Nothing -> None Just rev -> case DHM.search h rev of DHM.N -> case mstatic of DHM.N -> None DHM.K sidx -> KeyOnly InStaticTable (fromSIndexToIndex hdrtbl sidx) DHM.KV sidx -> KeyValue InStaticTable (fromSIndexToIndex hdrtbl sidx) DHM.K hidx -> case mstatic of DHM.N -> KeyOnly InDynamicTable (fromHIndexToIndex hdrtbl hidx) DHM.K sidx -> KeyOnly InStaticTable (fromSIndexToIndex hdrtbl sidx) DHM.KV sidx -> KeyValue InStaticTable (fromSIndexToIndex hdrtbl sidx) DHM.KV hidx -> case mstatic of DHM.N -> KeyValue InDynamicTable (fromHIndexToIndex hdrtbl hidx) DHM.K _ -> KeyValue InDynamicTable (fromHIndexToIndex hdrtbl hidx) DHM.KV sidx -> KeyValue InStaticTable (fromSIndexToIndex hdrtbl sidx) where mstatic = DHM.search h staticHashPSQ ---------------------------------------------------------------- isIn :: Int -> DynamicTable -> Bool isIn idx DynamicTable{..} = idx > staticTableSize -- | Which table does 'Index' belong to? which :: DynamicTable -> Index -> IO (WhichTable, Entry) which hdrtbl idx | idx `isIn` hdrtbl = (InDynamicTable,) <$> toHeaderEntry hdrtbl hidx | isSIndexValid sidx = return (InStaticTable, toStaticEntry sidx) | otherwise = throwIO $ IndexOverrun idx where hidx = fromIndexToHIndex hdrtbl idx sidx = fromIndexToSIndex hdrtbl idx
bergmark/http2
Network/HPACK/Table.hs
bsd-3-clause
2,832
0
16
621
636
343
293
51
10
module Data.Conduit.Network.Julius.Types ( ) where import Data.Text(Text) data JuliusMessage = StartProc | EndProc | StartRecog | EndRecog | IStatus {inputStatus :: InputStatus, time :: Int} | InputParam {frames :: Int, msec :: Int} | GMM {gmmResult :: Text, cmScore :: Double} | RecogOut {recogOut :: RecognitionOut} | RecogFail | Rejected {reason :: Text} data InputStatus = Listen | StartRec | EndRec type RecognitionOut = [Shypo] data Shypo = Shypo {rank :: Int ,score :: Double ,gram :: Int ,whypos :: [Whypo] } data Whypo = Whypo {word :: Text ,classId :: Int ,phone :: Text ,cm :: Double } sentenceWords :: Shypo -> [Text] sentenceWords = whyposWords . whypos whyposWords :: [Whypo] -> [Text] whyposWords = map word
haru2036/julius-client-hs
Data/Conduit/Network/Julius/Types.hs
bsd-3-clause
1,096
0
9
491
249
157
92
26
1
module Main where import Day5 main :: IO () main = do putStrLn $ getPasswd' 8 0 "cxdnnyjw"
reidwilbur/aoc2016
app/Main.hs
bsd-3-clause
94
0
8
21
36
19
17
5
1
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE BangPatterns #-} -- Copyright : Erik de Castro Lopo <[email protected]> -- License : BSD3 module Network.Wai.Handler.Warp.ReadInt ( readInt , readInt64 ) where import qualified Data.ByteString as S import Network.Wai.Handler.Warp.Imports hiding (readInt) {-# INLINE readInt #-} readInt :: Integral a => ByteString -> a readInt bs = fromIntegral $ readInt64 bs -- This function is used to parse the Content-Length field of HTTP headers and -- is a performance hot spot. It should only be replaced with something -- significantly and provably faster. -- -- It needs to be able work correctly on 32 bit CPUs for file sizes > 2G so we -- use Int64 here and then make a generic 'readInt' that allows conversion to -- Int and Integer. {-# NOINLINE readInt64 #-} readInt64 :: ByteString -> Int64 readInt64 bs = S.foldl' (\ !i !c -> i * 10 + fromIntegral (c - 48)) 0 $ S.takeWhile isDigit bs isDigit :: Word8 -> Bool isDigit w = w >= 48 && w <= 57
kazu-yamamoto/wai
warp/Network/Wai/Handler/Warp/ReadInt.hs
mit
1,029
0
12
210
177
103
74
16
1
{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE ScopedTypeVariables #-} module GHCJS.HPlay.View( Widget(..) -- * Running it , module Transient.Move.Utils , runBody , addHeader , render -- * Widget Combinators and Modifiers , (<<) , (<<<) , (<!) , (<++) , (++>) , validate , wcallback , redraw -- * Basic Widgets , option , wprint , getString , inputString , getInteger , inputInteger , getInt , inputInt , inputFloat , inputDouble , getPassword , inputPassword , setRadio , setRadioActive , getRadio , setCheckBox , getCheckBoxes , getTextBox , getMultilineText , textArea , getBool , getSelect , setOption , setSelectedOption , wlabel , resetButton , inputReset , submitButton , inputSubmit , wbutton , wlink , tlink , staticNav , noWidget , wraw , rawHtml , isEmpty -- * Events , BrowserEvent(..) -- * Out of Flow Updates , UpdateMethod(..) , setRenderTag , at, at' -- * Reactive and Events , IsEvent(..) , EventData(..) , EvData(..) , resetEventData , getEventData , setEventData , raiseEvent , fire , wake , pass -- * utility , clearScreen -- * Low-level and Internals , ElemID , getNextId , genNewId , continuePerch , getParam , getCont , runCont , elemById , withElem , getProp , setProp , alert , fromJSString , toJSString , getValue -- * Re-exported , module Control.Applicative , module GHCJS.Perch -- remove ,CheckBoxes(..) ,edit ,JSString,pack, unpack ,RadioId(..), Radio(..) ) where import Transient.Internals hiding (input, option, parent) import Transient.Logged import Transient.Move.Utils import qualified Prelude(id,span,div) #ifndef ghcjs_HOST_OS import Transient.Parse hiding(parseString) import Data.Char(isSpace) import System.Directory import System.IO.Error import Data.List(elemIndices) import Control.Exception hiding (try) import qualified Data.ByteString.Lazy.Char8 as BS #endif import Control.Monad.State -- import qualified Data.Map as M import Control.Applicative import Control.Concurrent import Data.Dynamic import Data.Maybe import Data.Monoid import Data.Typeable import Prelude hiding (id,span,div) import System.IO.Unsafe import Unsafe.Coerce import Data.IORef #ifdef ghcjs_HOST_OS import GHCJS.Foreign import GHCJS.Foreign.Callback import GHCJS.Foreign.Callback.Internal (Callback(..)) import GHCJS.Marshal import GHCJS.Perch hiding (JsEvent (..), eventName, option,head,map) import GHCJS.Types import Transient.Move hiding (pack) import qualified Data.JSString as JS hiding (empty, center,span, strip,foldr,head) import Data.JSString (pack,unpack,toLower) #else import Data.List as JS hiding (span) import GHCJS.Perch hiding (JSVal, JsEvent (..), eventName, option,head, map) import Transient.Move #endif #ifndef ghcjs_HOST_OS type JSString = String #else instance Loggable JSString #endif toJSString :: (Show a, Typeable a) => a -> JSString toJSString x = if typeOf x == typeOf (undefined :: String ) then pack $ unsafeCoerce x else pack$ show x fromJSString :: (Typeable a,Read a) => JSString -> a fromJSString s = x where x | typeOf x == typeOf (undefined :: JSString) = unsafeCoerce x -- !> "unsafecoerce" | typeOf x == typeOf (undefined :: String) = unsafeCoerce $ pack$ unsafeCoerce x -- !!> "packcoerce" | otherwise = read $ unpack s -- !> "readunpack" getValue :: MonadIO m => Elem -> m (Maybe String) getName :: MonadIO m => Elem -> m (Maybe String) #ifdef ghcjs_HOST_OS getValue e = liftIO $ do s <- getValueDOM e fromJSVal s -- return $ JS.unpack s getName e = liftIO $ do s <- getNameDOM e fromJSVal s #else getValue = undefined getName = undefined #endif elemBySeq :: (MonadState EventF m, MonadIO m) => JSString -> m (Maybe Elem) #ifdef ghcjs_HOST_OS elemBySeq id = do IdLine _ id1 <- getData `onNothing` error ("not found: " ++ show id) -- return (IdLine "none") return () !> ("elemBySeq",id1, id) liftIO $ do let id2= JS.takeWhile (/='p') id re <- elemBySeqDOM id1 id2 fromJSVal re #else elemBySeq _ = return Nothing #endif #ifdef ghcjs_HOST_OS attribute :: (MonadIO m) => Elem -> JSString -> m (Maybe JSString) attribute elem prop= liftIO $ do rv <- attributeDOM elem "id" fromJSVal rv #else attribute _ = return Nothing #endif elemById :: MonadIO m => JSString -> m (Maybe Elem) #ifdef ghcjs_HOST_OS elemById id= liftIO $ do re <- elemByIdDOM id fromJSVal re #else elemById _= return Nothing #endif withElem :: ElemID -> (Elem -> IO a) -> IO a withElem id f= do me <- elemById id case me of Nothing -> error ("withElem: not found"++ fromJSString id) Just e -> f e --data NeedForm= HasForm | HasElems | NoElems deriving Show type ElemID= JSString newtype Widget a= Widget{ norender :: TransIO a} deriving(Monad,MonadIO, Alternative, MonadState EventF,MonadPlus,Num) instance Functor Widget where fmap f mx= Widget. Transient $ fmap (fmap f) . runTrans $ norender mx instance Applicative Widget where pure= return Widget (Transient x) <*> Widget (Transient y) = Widget . Transient $ do getData `onNothing` do cont <- get let al= Alternative cont setData $ Alternative cont return al mx <- x my <- y return $ mx <*> my instance Monoid a => Monoid (Widget a) where mempty= return mempty #if MIN_VERSION_base(4,11,0) mappend= (<>) instance (Monoid a) => Semigroup (Widget a) where (<>)= mappendw #else mappend= mappendw #endif mappendw x y= (<>) <$> x <*> y instance AdditionalOperators Widget where Widget (Transient x) <** Widget (Transient y)= Widget . Transient $ do getData `onNothing` do cont <- get let al= Alternative cont setData $ Alternative cont return al mx <- x y return mx (<***) x y= Widget $ norender x <*** norender y (**>) x y= Widget $ norender x **> norender y runView :: Widget a -> StateIO (Maybe a) runView = runTrans . norender -- | It is a callback in the view monad. The rendering of the second parameter substitutes the rendering -- of the first paramenter when the latter validates without afecting the rendering of other widgets. wcallback :: Widget a -> (a ->Widget b) -> Widget b wcallback x f= Widget $ Transient $ do nid <- genNewId runView $ do r <- at nid Insert x at nid Insert $ f r -- | execute a widget but redraw itself too when some event happens. -- The first parameter is the path of the DOM element that hold the widget, used by `at` redraw :: JSString -> Widget a -> TransIO a redraw idelem w= do path <- getState <|> return ( Path []) r <- render $ at idelem Insert w setState path redraw idelem w <|> return r {- instance Monoid view => MonadTrans (View view) where lift f = Transient $ (lift f) >>= \x -> returnFormElm mempty $ Just x -} type Name= JSString type Type= JSString type Value= JSString type Checked= Bool type OnClick1= Maybe JSString -- | Minimal interface for defining the basic form and link elements. The core of MFlow is agnostic -- about the rendering package used. Every formatting (either HTML or not) used with MFlow must have an -- instance of this class. -- See "MFlow.Forms.Blaze.Html for the instance for blaze-html" "MFlow.Forms.XHtml" for the instance -- for @Text.XHtml@ and MFlow.Forms.HSP for the instance for Haskell Server Pages. -- class (Monoid view,Typeable view) => FormInput view where -- fromStr :: JSString -> view -- fromStrNoEncode :: String -> view -- ftag :: JSString -> view -> view -- inred :: view -> view -- flink :: JSString -> view -> view -- flink1:: JSString -> view -- flink1 verb = flink verb (fromStr verb) -- finput :: Name -> Type -> Value -> Checked -> OnClick1 -> view -- ftextarea :: JSString -> JSString -> view -- fselect :: JSString -> view -> view -- foption :: JSString -> view -> Bool -> view -- foption1 :: JSString -> Bool -> view -- foption1 val msel= foption val (fromStr val) msel -- formAction :: JSString -> JSString -> view -> view -- attrs :: view -> Attribs -> view type Attribs= [(JSString, JSString)] data ParamResult v a= NoParam | NotValidated String v | Validated a deriving (Read, Show) valToMaybe (Validated x)= Just x valToMaybe _= Nothing isValidated (Validated x)= True isValidated _= False fromValidated (Validated x)= x fromValidated NoParam= error "fromValidated : NoParam" fromValidated (NotValidated s err)= error $ "fromValidated: NotValidated "++ s getParam1 :: ( Typeable a, Read a, Show a) => Bool -> JSString -> StateIO (ParamResult Perch a) getParam1 exact par = do isTemplate <- liftIO $ readIORef execTemplate if isTemplate then return NoParam else do me <- if exact then elemById par else elemBySeq par !> ("looking for " ++ show par) case me of Nothing -> return NoParam Just e -> do v <- getValue e -- !!> ("exist" ++ show par) readParam v -- !!> ("getParam for "++ show v) type Params= Attribs readParam :: (Typeable a, Read a)=> Maybe String -> StateIO (ParamResult Perch a) readParam Nothing = return NoParam readParam (Just x1) = r where r= maybeRead x1 getType :: m (ParamResult v a) -> a getType= undefined x= getType r maybeRead str= do let typeofx = typeOf x if typeofx == typeOf ( undefined :: String) then return . Validated $ unsafeCoerce str -- !!> ("maybread string " ++ str) else if typeofx == typeOf(undefined :: JSString) then return . Validated $ unsafeCoerce $ pack str else case reads $ str of -- -- !!> ("read " ++ str) of [(x,"")] -> return $ Validated x -- !!> ("readsprec" ++ show x) _ -> do let err= inred $ "can't read \"" ++ str ++ "\" as type " ++ show (typeOf x) return $ NotValidated str err -- | Validates a form or widget result against a validating procedure -- -- @getOdd= getInt Nothing `validate` (\x -> return $ if mod x 2==0 then Nothing else Just "only odd numbers, please")@ validate :: Widget a -> (a -> StateIO (Maybe Perch)) -> Widget a validate w val= do idn <- Widget $ Transient $ Just <$> genNewId rawHtml $ span ! id idn $ noHtml x <- w Widget $ Transient $ do me <- val x case me of Just str -> do liftIO $ withElem idn $ build $ clear >> (inred str) return Nothing Nothing -> do liftIO $ withElem idn $ build clear return $ Just x -- | Generate a new string. Useful for creating tag identifiers and other attributes. -- -- if the page is refreshed, the identifiers generated are the same. {-#NOINLINE rprefix #-} rprefix= unsafePerformIO $ newIORef 0 #ifdef ghcjs_HOST_OS genNewId :: (MonadState EventF m, MonadIO m) => m JSString genNewId= do r <- liftIO $ atomicModifyIORef rprefix (\n -> (n+1,n)) n <- genId let nid= toJSString $ ('n':show n) ++ ('p':show r) nid `seq` return nid #else genNewId :: (MonadState EventF m, MonadIO m) => m JSString genNewId= return $ pack "" --getPrev :: StateIO JSString --getPrev= return $ pack "" #endif -- | get the next ideitifier that will be created by genNewId getNextId :: MonadState EventF m => m JSString getNextId= do n <- gets mfSequence return $ toJSString $ 'p':show n -- | Display a text box and return a non empty String getString :: Maybe String -> Widget String getString = getTextBox -- `validate` -- \s -> if Prelude.null s then return (Just $ fromStr "") -- else return Nothing inputString :: Maybe String -> Widget String inputString= getString -- | Display a text box and return an Integer (if the value entered is not an Integer, fails the validation) getInteger :: Maybe Integer -> Widget Integer getInteger = getTextBox inputInteger :: Maybe Integer -> Widget Integer inputInteger= getInteger -- | Display a text box and return a Int (if the value entered is not an Int, fails the validation) getInt :: Maybe Int -> Widget Int getInt = getTextBox inputInt :: Maybe Int -> Widget Int inputInt = getInt inputFloat :: Maybe Float -> Widget Float inputFloat = getTextBox inputDouble :: Maybe Double -> Widget Double inputDouble = getTextBox -- | Display a password box getPassword :: Widget String getPassword = getParam Nothing "password" Nothing inputPassword :: Widget String inputPassword= getPassword newtype Radio a= Radio a data RadioId= RadioId JSString deriving Typeable -- | Implement a radio button setRadio :: (Typeable a, Eq a, Show a,Read a) => Bool -> a -> Widget (Radio a) setRadio ch v = Widget $ Transient $ do RadioId name <- getData `onNothing` error "setRadio out of getRadio" id <- genNewId me <- elemBySeq id checked <- case me of Nothing -> return "" Just e -> liftIO $ getProp e "checked" let str = if typeOf v == typeOf(undefined :: String) then unsafeCoerce v else show v addSData ( finput id "radio" (toJSString str) ch Nothing `attrs` [("name",name)] :: Perch) if checked == "true" !> ("val",v) then Just . Radio . read1 . unpack <$> liftIO (getProp (fromJust me) "value") else return Nothing where read1 x=r where r= if typeOf r== typeOf (undefined :: String) then unsafeCoerce x else read x setRadioActive :: (Typeable a, Eq a, Show a,Read a) => Bool -> a -> Widget (Radio a) setRadioActive ch rs = setRadio ch rs `raiseEvent` OnClick -- | encloses a set of Radio boxes. Return the option selected getRadio :: [Widget (Radio a)] -> Widget a getRadio ws = do id <- genNewId setData $ RadioId id Radio x <- foldr (<|>) empty ws <*** delData (RadioId id) return x newtype CheckBoxes a= CheckBoxes [a] instance Monoid a => Monoid (CheckBoxes a) where mempty= CheckBoxes [] #if MIN_VERSION_base(4,11,0) mappend= (<>) instance (Monoid a) => Semigroup (CheckBoxes a) where (<>)= mappendch #else mappend= mappendch #endif mappendch (CheckBoxes x) (CheckBoxes y)= CheckBoxes (x ++ y) -- | present a checkbox setCheckBox :: (Typeable a , Show a) => Bool -> a -> Widget (CheckBoxes a) setCheckBox checked' v= Widget . Transient $ do n <- genNewId me <- elemBySeq n let showv= toJSString (if typeOf v == typeOf (undefined :: String) then unsafeCoerce v else show v) addSData $ ( finput n "checkbox" showv checked' Nothing :: Perch) case me of Nothing -> return Nothing Just e -> do checked <- liftIO $ getProp e "checked" return . Just . CheckBoxes $ if checked=="true" then [v] else [] -- Read the checkboxes getCheckBoxes :: Show a => Widget (CheckBoxes a) -> Widget [a] getCheckBoxes w = do CheckBoxes rs <- w return rs whidden :: (Read a, Show a, Typeable a) => a -> Widget a whidden x= res where res= Widget . Transient $ do n <- genNewId let showx= case cast x of Just x' -> x' Nothing -> show x r <- getParam1 False n `asTypeOf` typef res addSData (finput n "hidden" (toJSString showx) False Nothing :: Perch) return (valToMaybe r) where typef :: Widget a -> StateIO (ParamResult Perch a) typef = undefined getTextBox :: (Typeable a, Show a, Read a) => Maybe a -> Widget a getTextBox ms = getParam Nothing "text" ms getParam :: (Typeable a, Show a, Read a) => Maybe JSString -> JSString -> Maybe a -> Widget a getParam look type1 mvalue= Widget . Transient $ getParamS look type1 mvalue getParamS look type1 mvalue= do tolook <- case look of Nothing -> genNewId Just n -> return n let nvalue x = case x of Nothing -> mempty Just v -> if (typeOf v== typeOf (undefined :: String)) then pack(unsafeCoerce v) else if typeOf v== typeOf (undefined :: JSString) then unsafeCoerce v else toJSString $ show v -- !!> "show" -- setData HasElems r <- getParam1 (isJust look) tolook case r of Validated x -> do addSData (finput tolook type1 (nvalue $ Just x) False Nothing :: Perch) ; return $ Just x -- !!> "validated" NotValidated s err -> do addSData (finput tolook type1 (toJSString s) False Nothing <> err :: Perch); return Nothing NoParam -> do modify $ \s -> s{execMode=Parallel};addSData (finput tolook type1 (nvalue mvalue) False Nothing :: Perch); return Nothing -- | Display a multiline text box and return its content getMultilineText :: JSString -> Widget String getMultilineText nvalue = res where res= Widget. Transient $ do tolook <- genNewId !> "GETMULTI" r <- getParam1 False tolook `asTypeOf` typef res case r of Validated x -> do addSData (ftextarea tolook $ toJSString x :: Perch); return $ Just x !> "VALIDATED" NotValidated s err -> do addSData (ftextarea tolook (toJSString s) :: Perch); return Nothing !> "NOTVALIDATED" NoParam -> do modify $ \s -> s{execMode=Parallel};addSData (ftextarea tolook nvalue :: Perch); return Nothing !> "NOTHING" where typef :: Widget String -> StateIO (ParamResult Perch String) typef = undefined -- | A synonim of getMultilineText textArea :: JSString ->Widget String textArea= getMultilineText getBool :: Bool -> String -> String -> Widget Bool getBool mv truestr falsestr= do r <- getSelect $ setOption truestr (fromStr $ toJSString truestr) <! (if mv then [("selected","true")] else []) <|> setOption falsestr(fromStr $ toJSString falsestr) <! if not mv then [("selected","true")] else [] if r == truestr then return True else return False -- | Display a dropdown box with the options in the first parameter is optionally selected -- . It returns the selected option. getSelect :: (Typeable a, Read a,Show a) => Widget (MFOption a) -> Widget a getSelect opts = res where res= Widget . Transient $ do tolook <- genNewId -- st <- get -- setData HasElems r <- getParam1 False tolook `asTypeOf` typef res -- setData $ fmap MFOption $ valToMaybe r runView $ fselect tolook <<< opts -- return $ valToMaybe r where typef :: Widget a -> StateIO (ParamResult Perch a) typef = undefined newtype MFOption a = MFOption a deriving Typeable instance Monoid a => Monoid (MFOption a) where mempty= MFOption mempty #if MIN_VERSION_base(4,11,0) mappend= (<>) instance (Monoid a) => Semigroup (MFOption a) where (<>)= mappendop #else mappend= mappendop #endif mappendop (MFOption x) (MFOption y)= MFOption (x <> y) -- | Set the option for getSelect. Options are concatenated with `<|>` setOption :: (Show a, Eq a, Typeable a) => a -> Perch -> Widget (MFOption a) setOption n v = setOption1 n v False -- | Set the selected option for getSelect. Options are concatenated with `<|>` setSelectedOption :: (Show a, Eq a, Typeable a) => a -> Perch -> Widget (MFOption a) setSelectedOption n v= setOption1 n v True setOption1 :: (Typeable a, Eq a, Show a) => a -> Perch -> Bool -> Widget (MFOption a) setOption1 nam val check= Widget . Transient $ do let n = if typeOf nam == typeOf(undefined :: String) then unsafeCoerce nam else show nam addSData (foption (toJSString n) val check) return Nothing -- (Just $ MFOption nam) wlabel:: Perch -> Widget a -> Widget a wlabel str w = Widget . Transient $ do id <- getNextId runView $ (ftag "label" str `attrs` [("for",id)] :: Perch) ++> w -- passive reset button. resetButton :: JSString -> Widget () resetButton label= Widget . Transient $ do addSData (finput "reset" "reset" label False Nothing :: Perch) return $ Just () inputReset :: JSString -> Widget () inputReset= resetButton -- passive submit button. Submit a form, but it is not trigger any event. -- Unless you attach it with `raiseEvent` submitButton :: (Read a, Show a, Typeable a) => a -> Widget a submitButton label= getParam Nothing "submit" $ Just label inputSubmit :: (Read a, Show a, Typeable a) => a -> Widget a inputSubmit= submitButton -- | active button. When clicked, return the first parameter wbutton :: a -> JSString -> Widget a wbutton x label= Widget $ Transient $ do idn <- genNewId runView $ do input ! atr "type" "submit" ! id idn ! atr "value" label `pass` OnClick return x `continuePerch` idn clearScreen= local $ do render . wraw $ forElems "body" $ this >> clear `child` (div ! atr "id" "body1" $ noHtml) setRenderTag "body1" -- | when creating a complex widget with many tags, this call indentifies which tag will receive the attributes of the (!) operator. continuePerch :: Widget a -> ElemID -> Widget a continuePerch w eid= c <<< w where c f =Perch $ \e' -> do build f e' elemid eid elemid id= elemById id >>= return . fromJust -- child e = do -- jsval <- firstChild e -- fromJSValUnchecked jsval rReadIndexPath= unsafePerformIO $ newIORef 0 -- | Present a link. It return the first parameter and execute the continuation when it is clicked. -- -- It also update the path in the URL. wlink :: (Show a, Typeable a) => a -> Perch -> Widget a #ifdef ghcjs_HOST_OS wlink x v= do (a ! href "#" $ v) `pass` OnClick Path paths <- Widget $ getSData <|> return (Path []) let paths'= paths ++ [ toLower $ JS.pack $ show1 x ] setData $ Path paths' -- !> ("paths", paths') let fpath= ("/" <> (Prelude.foldl (\p p' -> p <> "/" <> p') (head paths') $ tail paths')<> ".html") liftIO $ replaceState "" "" fpath return x #else wlink _ _= empty #endif show1 :: (Typeable a,Show a) => a -> String show1 x | typeOf x== typeOf (undefined :: String) = unsafeCoerce x | otherwise= show x data Path= Path [JSString] --pathLength= unsafePerformIO $ newIORef 0 -- | avoid that a recursive widget with links may produce long paths. It is equivalent to tail call elimination staticNav x= do Path paths <- getState <|> return (Path []) x <*** setState (Path paths) -- | template link. Besides the wlink behaviour, it loads the page from the server if there is any -- -- the page may have been saved with `edit` tlink :: (Show a, Typeable a) => a -> Perch -> Widget a tlink x v= Widget $ let showx= show1 x in do logged $ norender $ wlink showx v runCloud readPage return x <|> getPath showx where show1 x | typeOf x== typeOf (undefined :: String) = unsafeCoerce x | otherwise= show x readPage :: Cloud () readPage = do url <- local $ do Path path <- getSData <|> return (Path []) return $ (Prelude.foldl (\p p' -> p <> "/" <> p') (head path) $ tail path) mr <- atRemote $ local $ #ifndef ghcjs_HOST_OS do let url' = if url =="" then "/index" else url :: String let file= "static/out.jsexe/"++ url' ++ ".html" r <- liftIO $ doesFileExist file if r then do s <- liftIO $ BS.readFile file Just <$> do r <- filterBody s -- !> "exist" return r -- !> ("filtered",r) else return Nothing -- !> "do not exist" #else return Nothing #endif case mr of Nothing -> return () -- !> "readpage return" Just bodycontent -> do #ifdef ghcjs_HOST_OS local $ do liftIO $ forElems_ "body" $ this `setHtml` bodycontent -- !> bodycontent local $do installHandlers -- !> "installHanders" delData ExecEvent liftIO $ writeIORef execTemplate True return() #else localIO $ return() localIO $ return() return () #endif #ifdef ghcjs_HOST_OS installHandlers= do setData $ IdLine 0 "n0p0" EventSet hs <- liftIO $ readIORef eventRef -- <- getSData <|> return (EventSet []) mapM_ f hs -- !> ("installhandlers, length=", Prelude.length hs) where f (id, _, Event event, iohandler)= do me <- elemBySeq id case me of Nothing -> return() -- !> ("installHandlers: not found", id) -- error $ "not found: "++ show id Just e -> liftIO $ buildHandler e event iohandler -- !> ("installHandlers adding event to ", id) #endif -- getPath :: Read a => TransIO a #ifdef ghcjs_HOST_OS getPath segment= do -- return () !> "GETPATH" Path paths <- getSData <|> initPath l <- liftIO $ readIORef rReadIndexPath let pathelem= paths !! l lpath= Prelude.length paths if l >= lpath then empty -- !> "getPath empty" else do -- setData ExecTemplate !> "SET EXECTEMPLATE 2" -- liftIO $ writeIORef execTemplate True if unpack pathelem /= segment then empty else do liftIO $ writeIORef rReadIndexPath $ l + 1 asynchronous setData $ Path paths return x -- !> ("getPath return", x) -- liftIO $ writeIORef rReadIndexPath $ l +1 -- r <- async . return . read $ unpack pathelem -- !> ("pathelem=",pathelem) -- setData $ Path paths -- return r where asynchronous= async $ return () initPath= do path1 <- liftIO $ js_path >>= fromJSValUnchecked return $ Path $ split $ JS.drop 1 path1 split x= if JS.null x then [] else let (f,s) = JS.break (=='/') x in if JS.null s then let l1= JS.length f in [JS.take (l1-5) f] else f:split (JS.drop 1 s) #else getPath _= empty #endif #ifndef ghcjs_HOST_OS filterBody :: BS.ByteString -> TransIO BS.ByteString filterBody page= do setData $ ParseContext (error "parsing page") page -- !> "filterBody" dropTill "<body>" -- !> "token body" dropTill "</script>" -- !> "tojen script" stringTill parseString (token "</body>") -- !> "stringTill" stringTill p end = scan where scan= parseString <> ((try end >> return mempty) <|> scan) dropTill tok=do s <- parseString return () if s == tok then return () -- !> ("FOUND", tok) else dropTill tok token tok= do s <- parseString return () if s == tok then return () -- !> ("FOUND", tok) else empty parseString= do -- dropSpaces tTakeWhile (not . isSeparator) where isSeparator c= c == '>' --dropSpaces= parse $ \str ->((),BS.dropWhile isSpace str) -- tTakeWhile :: (Char -> Bool) -> TransIO BS.ByteString -- tTakeWhile cond= parse (span' cond) -- where -- span' cond s= -- let (h,t) = BS.span cond s -- c= BS.head t -- in (BS.snoc h c,BS.drop 1 t) -- parse :: (BS.ByteString -> (b, BS.ByteString)) -> TransIO b -- parse split= do -- ParseContext readit str <- getSData -- <|> error "parse: ParseContext not found" -- :: TransIO (ParseContext BS.ByteString) -- if BS.null str then empty else do -- let (ret,str3) = split str -- setData $ ParseContext readit str3 -- return ret #endif -- | show something enclosed in the <pre> tag, so ASCII formatting chars are honored wprint :: ToElem a => a -> Widget () wprint = wraw . pre -- | Enclose Widgets within some formating. -- @view@ is intended to be instantiated to a particular format -- -- NOTE: It has a infix priority : @infixr 5@ less than the one of @++>@ and @<++@ of the operators, so use parentheses when appropriate, -- unless the we want to enclose all the widgets in the right side. -- Most of the type errors in the DSL are due to the low priority of this operator. -- (<<<) :: (Perch -> Perch) -> Widget a -> Widget a (<<<) v form= Widget . Transient $ do rest <- getData `onNothing` return noHtml delData rest mx <- runView form f <- getData `onNothing` return noHtml setData $ rest <> v f return mx infixr 5 <<< -- | A parameter application with lower priority than ($) and direct function application (<<) :: (Perch -> Perch) -> Perch -> Perch (<<) tag content= tag $ toElem content infixr 7 << -- | Append formatting code to a widget -- -- @ getString "hi" <++ H1 << "hi there"@ -- -- It has a infix prority: @infixr 6@ higuer that '<<<' and most other operators (<++) :: Widget a -> Perch -> Widget a (<++) form v= Widget . Transient $ do mx <- runView form addSData v return mx infixr 6 ++> infixr 6 <++ -- | Prepend formatting code to a widget -- -- @bold << "enter name" ++> getString Nothing @ -- -- It has a infix prority: @infixr 6@ higher that '<<<' and most other operators (++>) :: Perch -> Widget a -> Widget a html ++> w = Widget . Transient $ do addSData html runView w -- | Add attributes to the topmost tag of a widget -- it has a fixity @infix 8@ infixl 8 <! widget <! attribs= Widget . Transient $ do rest <- getData `onNothing` return mempty delData rest mx <- runView widget fs <- getData `onNothing` return (mempty :: Perch) setData $ rest <> (fs `attrs` attribs :: Perch) return mx instance Attributable (Widget a) where (!) widget atrib = Widget $ Transient $ do -- widget <! [atrib] rest <- getData `onNothing` return (mempty:: Perch) delData rest mx <- runView widget fs <- getData `onNothing` return (mempty :: Perch) setData $ do rest ; (child $ mspan "noid" fs) ! atrib :: Perch return mx where child render = Perch $ \e -> do e' <- build render e jsval <- firstChild e' fromJSValUnchecked jsval instance Attributable (Perch -> Widget a) where w ! attr = \p -> w p ! attr mspan id cont= Perch $ \e -> do n <- liftIO $ getName e -- alert $ toJSString $ show n if n == Just "EVENT" then build cont e else build (nelem' "event" ! atr "id" id $ cont) e where nelem' x cont= nelem x `child` cont -- | Empty widget that does not validate. May be used as \"empty boxes\" inside larger widgets. -- -- It returns a non valid value. noWidget :: Widget a noWidget= Control.Applicative.empty -- | Render raw view formatting. It is useful for displaying information. wraw :: Perch -> Widget () wraw x= Widget $ addSData x >> return () -- x ++> return () -- | wraw synonym rawHtml= wraw -- | True if the widget has no valid input isEmpty :: Widget a -> Widget Bool isEmpty w= Widget $ Transient $ do mv <- runView w return $ Just $ isNothing mv ------------------------- fromStr = toElem -- fromStrNoEncode = toElem ftag n v = nelem n `child` v attrs tag [] = tag attrs tag (nv:attribs) = attrs (attr tag nv) attribs inred msg= ftag "b" msg `attrs` [("style","color:red")] finput n t v f c= let tag= input ! atr "type" t ! id n ! atr "value" v tag1= if f then tag ! atr "checked" "" else tag in case c of Just s -> tag1 ! atr "onclick" s; _ -> tag1 ftextarea nam text= textarea ! id nam $ text fselect nam list = select ! id nam $ list foption name v msel= let tag= nelem "option" ! atr "value" name `child` v in if msel then tag ! atr "selected" "" else tag -- formAction action method1 form = ftag "form" mempty `attrs` [("acceptCharset", "UTF-8") -- ,( "action", action) -- ,("method", method1)] -- `child` form -- flink v str = ftag "a" mempty `attrs` [("href", v)] `child` str --------------------------- data EvData = NoData | Click Int (Int, Int) | Mouse (Int, Int) | MouseOut | Key Int deriving (Show,Eq,Typeable) resetEventData :: Widget () resetEventData= Widget . Transient $ do setData $ EventData "Onload" $ toDyn NoData return $ Just () -- !!> "RESETEVENTDATA" getEventData :: Widget EventData getEventData = Widget getSData <|> return (EventData "Onload" $ toDyn NoData) -- (error "getEventData: event type not expected") setEventData :: EventData -> Widget () setEventData = Widget . setData class Typeable a => IsEvent a where eventName :: a -> JSString buildHandler :: Elem -> a ->(EventData -> IO()) -> IO() data BrowserEvent= OnLoad | OnUnload | OnChange | OnFocus | OnMouseMove | OnMouseOver | OnMouseOut | OnClick | OnDblClick | OnMouseDown | OnMouseUp | OnBlur | OnKeyPress | OnKeyUp | OnKeyDown deriving (Show, Typeable) data EventData= EventData{ evName :: JSString, evData :: Dynamic} deriving (Show,Typeable) --data OnLoad= OnLoad instance IsEvent BrowserEvent where -- data EData _= EventData{ evName :: JSString, evData :: EvData} deriving (Show,Typeable) eventName e = #ifdef ghcjs_HOST_OS JS.toLower $ JS.drop 2 (toJSString $ show e) -- const "load" #else "" #endif buildHandler elem e io = case e of OnLoad -> do cb <- syncCallback1 ContinueAsync (const $ setDat elem (io (EventData (eventName e) $ toDyn NoData)) ) js_addEventListener elem (eventName e) cb --data OnUnload = OnUnLoad --instance IsEvent OnUnload where -- eventName= const "unload" -- buildHandler elem e io = do OnUnload -> do cb <- syncCallback1 ContinueAsync (const $ setDat elem $ io (EventData (eventName e) $ toDyn NoData) ) js_addEventListener elem (eventName e) cb --data OnChange= OnChange --instance IsEvent OnChange where -- eventName= const "onchange" -- buildHandler elem e io = do OnChange -> do cb <- syncCallback1 ContinueAsync (const $ setDat elem $ io (EventData (eventName e) $ toDyn NoData) ) js_addEventListener elem (eventName e) cb --data OnFocus= OnFocus --instance IsEvent OnFocus where -- eventName= const "focus" -- buildHandler elem e io = do OnFocus -> do cb <- syncCallback1 ContinueAsync (const $ setDat elem $ io (EventData (eventName e) $ toDyn NoData) ) js_addEventListener elem (eventName e) cb --data OnBlur= OnBlur --instance IsEvent OnBlur where -- eventName= const "blur" -- buildHandler elem e io = do OnBlur -> do cb <- syncCallback1 ContinueAsync (const $ setDat elem $ io (EventData (eventName e)$ toDyn NoData) ) js_addEventListener elem (eventName e) cb --data OnMouseMove= OnMouseMove Int Int --instance IsEvent OnMouseMove where -- eventName= const "mousemove" -- buildHandler elem e io= do OnMouseMove -> do cb <- syncCallback1 ContinueAsync (\r -> do (x,y) <-fromJSValUnchecked r stopPropagation r setDat elem $ io $ EventData (eventName e) $ toDyn $ Mouse(x,y)) js_addEventListener elem (eventName e) cb --data OnMouseOver= OnMouseOver --instance IsEvent OnMouseOver where -- eventName= const "mouseover" -- buildHandler elem e io= do OnMouseOver -> do cb <- syncCallback1 ContinueAsync (\r -> do (x,y) <-fromJSValUnchecked r stopPropagation r setDat elem $ io $ EventData (nevent e) $ toDyn $ Mouse(x,y)) js_addEventListener elem (eventName e) cb --data OnMouseOut= OnMouseOut --instance IsEvent OnMouseOut where -- eventName= const "mouseout" -- buildHandler elem e io = do OnMouseOut -> do cb <- syncCallback1 ContinueAsync (const $ setDat elem $ io (EventData (nevent e) $ toDyn $ NoData) ) js_addEventListener elem (eventName e) cb --data OnClick= OnClick -- --instance IsEvent OnClick where -- eventName= const "click" -- buildHandler elem e io= do OnClick -> do cb <- syncCallback1 ContinueAsync $ \r -> do (i,x,y)<- fromJSValUnchecked r stopPropagation r setDat elem $ io $ EventData (nevent e) $ toDyn $ Click i (x,y) js_addEventListener elem (eventName e) cb --data OnDblClick= OnDblClick --instance IsEvent OnDblClick where -- eventName= const "dblclick" -- buildHandler elem e io= do OnDblClick -> do cb <- syncCallback1 ContinueAsync $ \r -> do (i,x,y)<- fromJSValUnchecked r stopPropagation r setDat elem $ io $ EventData (nevent e) $ toDyn $ Click i (x,y) js_addEventListener elem (eventName e) cb -- --data OnMouseDown= OnMouseDown --instance IsEvent OnMouseDown where -- eventName= const "mousedowm" -- buildHandler elem e io= do OnMouseDown -> do cb <- syncCallback1 ContinueAsync $ \r -> do (i,x,y)<- fromJSValUnchecked r stopPropagation r setDat elem $ io $ EventData (nevent e) $ toDyn $ Click i (x,y) js_addEventListener elem (eventName e) cb --data OnMouseUp= OnMouseUp --instance IsEvent OnMouseUp where -- eventName= const "mouseup" -- buildHandler elem e io= do OnMouseUp -> do cb <- syncCallback1 ContinueAsync $ \r -> do (i,x,y)<- fromJSValUnchecked r stopPropagation r setDat elem $ io $ EventData (nevent e) $ toDyn $ Click i (x,y) js_addEventListener elem (eventName e) cb --data OnKeyPress= OnKeyPress --instance IsEvent OnKeyPress where -- eventName= const "keypress" -- buildHandler elem e io = do OnKeyPress -> do cb <- syncCallback1 ContinueAsync $ \r -> do i <- fromJSValUnchecked r stopPropagation r setDat elem $ io $ EventData (nevent e) $ toDyn $ Key i js_addEventListener elem (eventName e) cb --data OnKeyUp= OnKeyUp --instance IsEvent OnKeyUp where -- eventName= const "keyup" -- buildHandler elem e io = do OnKeyUp -> do cb <- syncCallback1 ContinueAsync $ \r -> do i <- fromJSValUnchecked r stopPropagation r setDat elem $ io $ EventData (nevent e) $ toDyn $ Key i js_addEventListener elem (eventName e) cb --data OnKeyDown= OnKeyDown --instance IsEvent OnKeyDown where -- eventName= const "keydown" -- buildHandler elem e io = do OnKeyDown -> do cb <- syncCallback1 ContinueAsync $ \r -> do i <- fromJSValUnchecked r stopPropagation r setDat elem $ io $ EventData (nevent e) $ toDyn $ Key i js_addEventListener elem (eventName e) cb where nevent = eventName setDat :: Elem -> IO() -> IO () setDat elem action = do action -- !!> "begin action" return () -- !!> "end action" addSData :: (MonadState EventF m,Typeable a ,Monoid a) => a -> m () addSData y= do x <- getData `onNothing` return mempty setData (x <> y) -- stores the identifier of the element to append new rendering -- must be an identifier instead of an DOM element since links may reload the whole page data IdLine= IdLine Int JSString -- deriving(Read,Show) data ExecMode= ExecEvent deriving (Eq, Read, Show) execTemplate= unsafePerformIO $ newIORef False -- first identifier for an applicative widget expression -- needed for applictives in the widget monad that are executed differently than in the TransIO monad -- newtype IDNUM = IDNUM Int deriving Show data Event= forall ev.IsEvent ev => Event ev data EventSet= EventSet [(JSString, Int, Event, ( EventData -> IO ()))] deriving Typeable {-# NOINLINE eventRef #-} eventRef= unsafePerformIO $ newIORef $ EventSet [] -- | triggers the event that happens in a widget. The effects are the following: -- -- 1)The event reexecutes the monadic sentence where the widget is, (with no re-rendering) -- -- 2) with the result of this reevaluaution of 1), the rest of the monadic computation is executed -- -- 3) update the DOM tree with the rendering generated by the reevaluation of 2). -- -- As usual, If one step of the monadic computation return `empty` (`stop`), the reevaluation finish -- So the effect of an event can be restricted as much as you may need. -- -- The part of the monadic expression that is before the event is not evaluated and his rendering is untouched. -- (but, at any moment, you can choose the element to be updated in the page using `at`) -- to store the identifier number of the form elements to be set for that event raiseEvent :: IsEvent event => Widget a -> event -> Widget a #ifdef ghcjs_HOST_OS raiseEvent w event = Widget . Transient $ do Alternative cont <- getData `onNothing` (Alternative <$> get) let iohandler :: EventData -> IO () iohandler eventdata =do runStateT (setData eventdata >> runCont' cont) cont -- !> "runCont INIT" return () -- !> "runCont finished" id <- genNewId let id'= JS.takeWhile (/='p') id addEventList id' event iohandler template <-liftIO $ readIORef execTemplate if not template then runView $ addEvent id event iohandler <<< w else do me <- elemBySeq id' -- !> ("adding event to", id') case me of Nothing -> runView $ addEvent id event iohandler <<< w !> "do not exist, creating elem" Just e -> do mr <- getData !> "exist adding event to current element" when (mr /= Just ExecEvent) $ liftIO (buildHandler e event iohandler) r <- runView w delData noHtml return r where -- to restore event handlers when a new template is loaded addEventList a b c= do IdLine level _ <- getData `onNothing` error "IdLine not set" liftIO $ atomicModifyIORef eventRef $ \(EventSet mlist) -> let (cut,rest)= Prelude.span (\(x,l,_,_) -> x < a) mlist rest'= Prelude.takeWhile(\(_,l,_,_) -> l <= level) $ tail1 rest in (EventSet $ cut ++ (a,level, Event b, c):rest' ,()) tail1 []= [] tail1 xs= tail xs runCont' cont= do setData ExecEvent -- !> "REPEAT: SET EXECEVENT" liftIO $ writeIORef execTemplate False mr <- runClosure cont return () case mr of Nothing -> return Nothing Just r -> runContinuation cont r -- !> "continue" -- create an element and add any event handler to it. addEvent :: IsEvent a => JSString -> a -> (EventData -> IO()) -> Perch -> Perch addEvent id event iohandler be= Perch $ \e -> do e' <- build (mspan id be) e buildHandler e' event iohandler return e #else raiseEvent w _ = w #endif #ifdef ghcjs_HOST_OS foreign import javascript unsafe "$1.stopPropagation()" stopPropagation :: JSVal -> IO () #else stopPropagation= undefined #endif -- | A shorter synonym for `raiseEvent` fire :: IsEvent event => Widget a -> event -> Widget a fire = raiseEvent -- | A shorter and smoother synonym for `raiseEvent` wake :: IsEvent event => Widget a -> event -> Widget a wake = raiseEvent -- | pass trough only if the event is fired in this DOM element. -- Otherwise, if the code is executing from a previous event, the computation will stop pass :: IsEvent event => Perch -> event -> Widget EventData pass v event= do resetEventData wraw v `wake` event e@(EventData typ _) <- getEventData guard (eventName event== typ) return e -- | run the widget as the content of a DOM element -- the new rendering is added to the element runWidget :: Widget b -> Elem -> IO (Maybe b) runWidget action e = do (mx, s) <- runTransient . norender $ runWidget' action e return mx runWidget' :: Widget b -> Elem -> Widget b runWidget' action e = Widget $ Transient $ do mx <- runView action -- !> "runVidget'" render <- getData `onNothing` (return noHtml) liftIO $ build render e delData render return mx -- | add a header in the <header> tag addHeader :: Perch -> IO () #ifdef ghcjs_HOST_OS addHeader format= do head <- getHead build format head return () #else addHeader _ = return () #endif -- | run the widget as the body of the HTML. It adds the rendering to the body of the document. -- -- Use only for pure client-side applications, like the ones of <http://http://tryplayg.herokuapp.com> runBody :: Widget a -> IO (Maybe a) runBody w= do body <- getBody runWidget w body newtype AlternativeBranch= Alternative EventF deriving Typeable -- | executes the computation and add the effect of "hanging" the generated rendering from the one generated by the -- previous `render` sentence, or from the body of the document, if there isn't any. If an event happens within -- the `render` parameter, it deletes the rendering of all subsequent ones. -- so that the sucessive sequence of `render` in the code will reconstruct them again. -- However the rendering of elements combined with `<|>` or `<>` or `<*>` are independent. -- This allows for full dynamic and composable client-side Web apps. render :: Widget a -> TransIO a #ifdef ghcjs_HOST_OS render mx = Transient $ do isTemplate <- liftIO $ readIORef execTemplate !> "RENDER" idline1@(IdLine level id1') <- getData `onNothing` do id1 <- genNewId -- !> "ONNOTHING" -- if is being edited or not top <- liftIO $ (elemById "edited") `onNothing` getBody when (not isTemplate) $ do liftIO $ build (span ! id id1 $ noHtml) top return () return $ IdLine 0 id1 ma <- getData mw <- gets execMode id1 <- if (isJust (ma :: Maybe AlternativeBranch) || mw == Parallel ) !> (mw) then do id3 <- do id3 <- genNewId !> "ALTERNATIVE" -- create id3 hanging from id1 parent if (not isTemplate) then do liftIO $ withElem id1' $ build $ this `goParent` (span ! atr "ALTERNATIVE" "" ! id id3 $ noHtml) return id3 else do -- template look for real id3 me <- liftIO $ elemById id1' >>= \x -> case x of Nothing -> return Nothing Just x -> nextSibling x case me of Nothing -> return id3 -- should not happen Just e -> attribute e "id" >>= return . fromJust setData (IdLine level id3) !> ("setDataAL1",id3) delData $ Alternative undefined !> ("alternative, creating", id3) return id3 else setData idline1 >> return id1' id2 <- genNewId n <- gets mfSequence -- setData $ IDNUM n -- r <- runWidgetId' (mx' id1 id2 <++ (span ! id id2 $ noHtml)) id1 r <-runTrans $ norender mx <*** (Transient $ do meid2 <- elemBySeq id2 !> ("checking",id1,id2) case meid2 of Nothing -> return () Just eid2 -> do -- we are in a template. Look for the true id2 in it id2' <- attribute eid2 "id" >>= return . fromJust -- let n= read (tail $ JS.unpack $ JS.dropWhile (/= 'p') id2') + 1 -- liftIO $ writeIORef rprefix n !> ("N",n) (setData (IdLine (level +1) id2')) !> ("set IdLine",id2') execmode <- getData case execmode of Just ExecEvent -> do -- an event has happened. Clean previous rendering when (isJust meid2) $ liftIO $ do deleteSiblings $ fromJust meid2 !> "EVENT" clearChildren $ fromJust meid2 delData ExecEvent delData noHtml return () _ -> do return () !> ("EXECTEMPLATE", isTemplate) if isTemplate then delData noHtml else do render <- getData `onNothing` (return noHtml) -- !> "TEMPLATE" eid1 <- liftIO $ elemById id1 `onNothing` error ("not found: " ++ show id1) liftIO $ build (render <> (span ! id id2 $ noHtml)) eid1 -- setData (IdLine (level +1) id2 ) !> ("set2 idLine", id2) delData render return $ Just ()) if(isJust r) then delData (Alternative undefined) >> setData (IdLine (level +1) id2 ) -- !> ("setDataAl",id2) else do cont <- get setData (Alternative cont) !> "SETDATA ALTERNATIVE" return r #else render (Widget x)= empty #endif -- st@(EventF eff e x (fs) d n r applic ch rc bs) <- get -- let cont= EventF eff e x fs d n r applic ch rc bs -- put cont -- liftIO $ print ("length1",Prelude.length fs) -- | use this instead of `Transient.Base.option` when runing in the browser option :: (Typeable b, Show b) => b -> String -> Widget b option x v= wlink x (toElem v) <++ " " --foreign import javascript unsafe "document.body" getBody :: IO Elem data UpdateMethod= Append | Prepend | Insert deriving Show -- | set the tag where subsequent `render` calls will place HTML-DOM element setRenderTag :: MonadState EventF m => JSString -> m () setRenderTag id= modifyData' (\(IdLine level _) -> IdLine level id) (IdLine 0 id) >> return () -- | Run the widget as the content of the element with the given path identifier. The content can -- be appended, prepended to the previous content or it can erase the previous content depending on the -- update method. at :: JSString -> UpdateMethod -> Widget a -> Widget a at id method w= setAt id method <<< do original@(IdLine level i) <- Widget $ getState <|> error "IdLine not defined" setState $ IdLine level $ JS.tail id -- "n0p0" w `with` setState original where with (Widget (Transient x)) (Widget (Transient y))= Widget . Transient $ do mx <- x y return mx setAt :: JSString -> UpdateMethod -> Perch -> Perch setAt id method render = liftIO $ case method of Insert -> do forElems_ id $ clear >> render return () Append -> do forElems_ id render return () Prepend -> do forElems_ id $ Perch $ \e -> do jsval <- getChildren e es <- fromJSValUncheckedListOf jsval case es of [] -> build render e >> return e e':es -> do span <- newElem "span" addChildBefore span e e' build render span return e -- | a version of `at` for the Cloud monad. at' :: JSString -> UpdateMethod -> Cloud a -> Cloud a at' id method w= setAt id method `insert` w where insert v comp= Cloud . Transient $ do rest <- getData `onNothing` return noHtml delData rest mx <- runTrans $ runCloud comp f <- getData `onNothing` return noHtml setData $ rest <> v f return mx #ifdef ghcjs_HOST_OS foreign import javascript unsafe "$1[$2].toString()" getProp :: Elem -> JSString -> IO JSString foreign import javascript unsafe "$1[$2] = $3" setProp :: Elem -> JSString -> JSString -> IO () foreign import javascript unsafe "alert($1)" js_alert :: JSString -> IO () alert :: (Show a,MonadIO m) => a -> m () alert= liftIO . js_alert . pack . show foreign import javascript unsafe "document.getElementById($1)" elemByIdDOM :: JSString -> IO JSVal foreign import javascript unsafe "document.getElementById($1).querySelector(\"[id^='\"+$2+\"']\")" elemBySeqDOM :: JSString -> JSString -> IO JSVal foreign import javascript unsafe "$1.value" getValueDOM :: Elem -> IO JSVal foreign import javascript unsafe "$1.tagName" getNameDOM :: Elem -> IO JSVal foreign import javascript unsafe "$1.getAttribute($2)" attributeDOM :: Elem -> JSString -> IO JSVal #else unpack= undefined getProp :: Elem -> JSString -> IO JSString getProp = error "getProp: undefined in server" setProp :: Elem -> JSString -> JSString -> IO () setProp = error "setProp: undefined in server" alert :: (Show a,MonadIO m) => a -> m () alert= liftIO . print data Callback a= Callback a data ContinueAsync=ContinueAsync syncCallback1= undefined fromJSValUnchecked= undefined fromJSValUncheckedListOf= undefined #endif #ifdef ghcjs_HOST_OS foreign import javascript unsafe "$1.addEventListener($2, $3,false);" js_addEventListener :: Elem -> JSString -> Callback (JSVal -> IO ()) -> IO () #else js_addEventListener= undefined #endif #ifdef ghcjs_HOST_OS foreign import javascript unsafe "document.head" getHead :: IO Elem #else getHead= undefined #endif #ifdef ghcjs_HOST_OS foreign import javascript unsafe "$1.childNodes" getChildren :: Elem -> IO JSVal foreign import javascript unsafe "$1.firstChild" firstChild :: Elem -> IO JSVal foreign import javascript unsafe "$2.insertBefore($1, $3)" addChildBefore :: Elem -> Elem -> Elem -> IO() foreign import javascript unsafe "while ($1.nextSibling != null) {$1.parentNode.removeChild($1.nextSibling)};" deleteSiblings :: Elem -> IO () foreign import javascript unsafe "$1.nextSibling" js_nextSibling :: Elem -> IO JSVal nextSibling e= js_nextSibling e >>= fromJSVal #else type JSVal = () getChildren :: Elem -> IO JSVal getChildren= undefined firstChild :: Elem -> IO JSVal firstChild= undefined addChildBefore :: Elem -> Elem -> Elem -> IO() addChildBefore= undefined #endif ---------------------------- TEMPLATES & NAVIGATION --------------- editW :: Cloud String #ifdef ghcjs_HOST_OS editW = onBrowser $ loggedc $ do local $ do liftIO $ forElems_ "body" $ this `child` do div ! id "panel" $ noHtml div ! id "edit" $ div ! id "edited" $ center $ font ! atr "size" "2" ! atr "color" "red" $ p $ do "Edit this template" <> br "Add content, styles, layout" <> br "Navigate the links and save the edition for each link" <> br "Except this header, don't delete anything unless you know what you do" <> br "since the template has been generated by your code" <> br installnicedit liftIO $threadDelay 1000000 -- edit <- liftIO $ elemById "edit" >>= return . fromJust -- setState $ IdLine 0 "edit" react edit1 (return ()) :: TransIO () return "editw" where font ch= nelem "font" `child` ch edit1 :: (() -> IO ()) -> IO () edit1 f= do Callback cb <- syncCallback1 ContinueAsync $ \ _ -> f() js_edit cb installnicedit= do liftIO $ addHeader $ script ! id "nic" ! atr "type" "text/javascript" ! src "http://js.nicedit.com/nicEdit-latest.js" $ noHtml --manageNavigation= do -- Callback cb <- syncCallback1 ContinueAsync nav -- onpopstate cb -- where -- nav e= do -- location <- fromJSValUnchecked e -- alert location ----- pushstate foreign import javascript unsafe "window.onpopstate = function(event) { $1(document.location);}" onpopstate :: JSVal -> IO () foreign import javascript unsafe "window.history.pushState($1,$2,$3)" pushState :: JSString -> JSString -> JSString -> IO () foreign import javascript unsafe "window.history.replaceState($1,$2,$3)" replaceState :: JSString -> JSString -> JSString -> IO () foreign import javascript unsafe "document.getElementById('edit').innerHTML" js_getPage :: IO JSVal foreign import javascript safe "window.location.pathname" js_path :: IO JSVal foreign import javascript unsafe "var myNicEditor = new nicEditor({fullPanel : true, onSave : $1});myNicEditor.addInstance('edit');myNicEditor.setPanel('panel');" js_edit :: JSVal -> IO () -- "var myNicEditor = new nicEditor({fullPanel : true, onSave : function(content, id, instance) {myNicEditor.removeInstance('edit');myNicEditor.removePanel('panel');}});myNicEditor.addInstance('edit');myNicEditor.setPanel('panel');" #else --manageNavigation :: IO () --manageNavigation = undefined pushState _ _ _= empty replaceState _ _ _= empty editW = onBrowser $ local empty -- !> "editW" js_getPage= empty js_path= empty #endif -- | edit and save the rendering of the widgets. -- -- The edited content may be saved to a file with th current route by the save option of the editor. -- `tlink` will load this page. Also when this route is requested, the server will return this page. edit w= do b <- localIO $ elemById "edited" >>= return . isJust if b then do local $ do -- modify (\s -> s{mfSequence=2}) -- ******* -- liftIO $ writeIORef rprefix 2 -- setData ExecTemplate !> "SET EXECTEMPLATE 1" liftIO $ writeIORef execTemplate True -- setData $ IdLine 0 "n0p0" -- local addPrefix w else do edit' <|> w where edit' = do editW page <- localIO $ js_getPage >>= fromJSValUnchecked :: Cloud String url <- localIO $ js_path >>= fromJSValUnchecked :: Cloud String atRemote $ localIO $ do #ifdef ghcjs_HOST_OS return () #else let url' = if url =="/" then "/index.html" else url :: String let page'= fullpage page -- return () !> ("----->",url') write ("static/out.jsexe"++ url') page' -- return () !> "WRITTTEN" empty where write filename page= writeFile filename page `catch` (\e -> when ( isDoesNotExistError e) $ do let dir= take (1+(last $ elemIndices '/' filename)) filename return () -- !> ("create",dir) createDirectoryIfMissing True dir write filename page) fullpage page= "<!DOCTYPE html><html><head><script language=\"javascript\" src=\"rts.js\"></script><script language=\"javascript\" src=\"lib.js\"></script><script language=\"javascript\" src=\"out.js\"></script></head><body></body><script language=\"javascript\" src=\"runmain.js\" defer></script>" ++ page ++ "</body></html>" #endif
agocorona/ghcjs-hplay
src/GHCJS/HPlay/View.hs
mit
64,020
65
29
21,139
14,828
7,506
7,322
853
7
{-# LANGUAGE ScopedTypeVariables #-} module WeiXin.PublicPlatform.EndUser ( wxppQueryEndUserInfo , wxppBatchQueryEndUserInfo, wxppBatchQueryEndUserInfoMaxNum , wxppBatchQueryEndUserInfoConduit , GetUserResult(..) , wxppOpenIdListInGetUserResult , wxppGetEndUserSource , wxppGetEndUserSource' , wxppLookupAllCacheForUnionID , wxppCachedGetEndUserUnionID , wxppCachedQueryEndUserInfo , wxppCachedBatchQueryEndUserInfo , GroupBasicInfo(..) , wxppListUserGroups , wxppCreateUserGroup , wxppDeleteUserGroup , wxppRenameUserGroup , wxppGetGroupOfUser , wxppSetUserGroup , wxppBatchSetUserGroup ) where -- {{{1 imports import ClassyPrelude hiding ((\\)) #if MIN_VERSION_base(4, 13, 0) -- import Control.Monad (MonadFail(..)) #else import Control.Monad.Reader (asks) #endif import Network.Wreq hiding (Proxy) import qualified Network.Wreq.Session as WS import Control.Lens hiding ((.=)) import Control.Monad.Logger import Control.Monad.Trans.Maybe (runMaybeT, MaybeT(..)) import Data.Aeson import qualified Data.Conduit.List as CL import Data.Time (diffUTCTime, NominalDiffTime) import Data.List ((\\)) import Data.Conduit import Yesod.Helpers.Utils (nullToNothing) import WeiXin.PublicPlatform.Class import WeiXin.PublicPlatform.WS import Yesod.Compat -- }}}1 -- | 调用服务器接口,查询用户基础信息 wxppQueryEndUserInfo :: (WxppApiMonad env m) => AccessToken -> WxppOpenID -> m EndUserQueryResult wxppQueryEndUserInfo (AccessToken { accessTokenData = atk }) (WxppOpenID open_id) = do (sess, url_conf) <- asks (getWreqSession &&& getWxppUrlConfig) let url = wxppUrlConfSecureApiBase url_conf <> "/user/info" opts = defaults & param "access_token" .~ [ atk ] & param "openid" .~ [ open_id ] & param "lang" .~ [ "zh_CN" :: Text ] liftIO (WS.getWith opts sess url) >>= asWxppWsResponseNormal' newtype RespBatchQueryEndUserInfo = RespBatchQueryEndUserInfo { unRespBatchQueryEndUserInfo :: [EndUserQueryResult] } instance FromJSON RespBatchQueryEndUserInfo where parseJSON = withObject "EndUserQueryResult" $ \ o -> do RespBatchQueryEndUserInfo <$> o .: "user_info_list" -- | 调用服务器接口,批量查询用户基础信息 wxppBatchQueryEndUserInfo :: (WxppApiMonad env m) => AccessToken -> [WxppOpenID] -- ^ can be more than wxppBatchQueryEndUserInfoMaxNum -> m (Map WxppOpenID EndUserQueryResult) -- {{{1 wxppBatchQueryEndUserInfo (AccessToken { accessTokenData = atk }) open_ids0 = do (sess, url_conf) <- asks (getWreqSession &&& getWxppUrlConfig) let url = wxppUrlConfSecureApiBase url_conf <> "/user/info/batchget" opts = defaults & param "access_token" .~ [ atk ] & param "lang" .~ [ "zh_CN" :: Text ] let one_batch open_ids = do if null open_ids then return mempty else do liftIO (WS.postWith opts sess url $ object [ "user_list" .= map to_jv open_ids ]) >>= asWxppWsResponseNormal' >>= return . unRespBatchQueryEndUserInfo >>= return . mapFromList . map (getWxppOpenID &&& id) let split_open_ids open_ids = if null open_ids then [] else let (lst1, lst2) = splitAt wxppBatchQueryEndUserInfoMaxNum open_ids in lst1 : split_open_ids lst2 fmap mconcat $ mapM one_batch (split_open_ids open_ids0) where to_jv open_id = object [ "lang" .= asText "zh_CN" , "openid" .= open_id ] -- }}}1 wxppBatchQueryEndUserInfoMaxNum :: Int wxppBatchQueryEndUserInfoMaxNum = 100 wxppBatchQueryEndUserInfoConduit :: (WxppApiMonad env m) => AccessToken -> ConduitC WxppOpenID m (Map WxppOpenID EndUserQueryResult) wxppBatchQueryEndUserInfoConduit atk = go where go = do part_res <- CL.isolate wxppBatchQueryEndUserInfoMaxNum .| do CL.consume >>= wxppBatchQueryEndUserInfo atk if null part_res then return () else yield part_res >> go data GetUserResult = GetUserResult Int -- total Int -- count [WxppOpenID] (Maybe WxppOpenID) -- next open id instance FromJSON GetUserResult where parseJSON = withObject "GetUserResult" $ \obj -> do total <- obj .: "total" count <- obj .: "count" -- 当没数据时,似乎平台会不发出 data 字段 m_data_obj <- obj .:? "data" lst <- case m_data_obj of Nothing -> return [] Just o -> map WxppOpenID <$> o .: "openid" -- 平台是用空字串表示结束的 next_openid <- fmap WxppOpenID . join . fmap nullToNothing <$> obj .:? "next_openid" return $ GetUserResult total count lst next_openid wxppOpenIdListInGetUserResult :: GetUserResult -> [WxppOpenID] wxppOpenIdListInGetUserResult (GetUserResult _ _ x _) = x -- | 调用服务器接口,查询所有订阅用户 wxppGetEndUserSource' :: (WxppApiMonad env m) => m AccessToken -- ^ 我们要反复取用 access token, 而且不确定用多长时间 -> SourceC m GetUserResult wxppGetEndUserSource' get_atk = do (sess, url_conf) <- asks (getWreqSession &&& getWxppUrlConfig) let url = wxppUrlConfSecureApiBase url_conf <> "/user/get" loop m_start_id = do AccessToken { accessTokenData = atk } <- lift get_atk let opts = defaults & param "access_token" .~ [ atk ] & (case m_start_id of Nothing -> id Just (WxppOpenID start_open_id) -> param "next_openid" .~ [ start_open_id ] ) r@(GetUserResult _ _ _ m_next_id) <- liftIO (WS.getWith opts sess url) >>= asWxppWsResponseNormal' yield r maybe (return ()) (loop . Just) m_next_id loop Nothing {-# DEPRECATED wxppGetEndUserSource "use wxppGetEndUserSource' instead" #-} wxppGetEndUserSource :: (WxppApiMonad env m) => AccessToken -> SourceC m GetUserResult wxppGetEndUserSource = wxppGetEndUserSource' . return -- | 只找 cache: 根据 app id, open_id 找 union id -- 因现在有不止一个 cache 表, 这个函数能找的都找 wxppLookupAllCacheForUnionID :: ( MonadIO m, WxppCacheTemp c) => c -> WxppAppID -> WxppOpenID -> m (Maybe WxppUnionID) wxppLookupAllCacheForUnionID cache app_id open_id = runMaybeT $ asum [ by_sns, by_normal ] where by_sns = do info <- fmap fst $ MaybeT $ liftIO $ wxppCacheGetSnsUserInfo cache app_id open_id "zh_CN" MaybeT $ return $ oauthUserInfoUnionID info by_normal = do info <- fmap fst $ MaybeT $ liftIO $ wxppCacheLookupUserInfo cache app_id open_id MaybeT $ return $ endUserQueryResultUnionID info -- | 取用户的 UnionID -- 先从缓存找,找不到或找到的记录太旧,则调用接口 -- 如果调用接口取得最新的数据,立刻缓存之 wxppCachedGetEndUserUnionID :: ( WxppApiMonad env m, WxppCacheTemp c) => c -> NominalDiffTime -> AccessToken -> WxppOpenID -> m (Maybe WxppUnionID) wxppCachedGetEndUserUnionID cache ttl atk open_id = do liftM endUserQueryResultUnionID $ wxppCachedQueryEndUserInfo cache ttl atk open_id -- | 取用户信息,优先查询cache wxppCachedQueryEndUserInfo :: (WxppApiMonad env m, WxppCacheTemp c) => c -> NominalDiffTime -> AccessToken -> WxppOpenID -> m EndUserQueryResult wxppCachedQueryEndUserInfo cache ttl atk open_id = do m_res <- liftIO $ wxppCacheLookupUserInfo cache app_id open_id now <- liftIO getCurrentTime let m_qres0 = case m_res of Just ((EndUserQueryResultNotSubscribed {}), _) -> -- never do negative cache Nothing Just (qres, ctime) -> if diffUTCTime now ctime > ttl then Nothing else Just qres Nothing -> Nothing case m_qres0 of Just qres -> return qres Nothing -> do qres <- wxppQueryEndUserInfo atk open_id liftIO $ wxppCacheSaveUserInfo cache app_id qres return qres where app_id = accessTokenApp atk -- | 批量取用户信息,优先查询cache wxppCachedBatchQueryEndUserInfo :: (WxppApiMonad env m, WxppCacheTemp c) => c -> NominalDiffTime -> AccessToken -> [WxppOpenID] -> m (Map WxppOpenID EndUserQueryResult) wxppCachedBatchQueryEndUserInfo cache ttl atk open_ids = do cached_results <- fmap catMaybes $ forM open_ids $ \ open_id -> do m_res <- liftIO $ wxppCacheLookupUserInfo cache app_id open_id now <- liftIO getCurrentTime return $ case m_res of Just ((EndUserQueryResultNotSubscribed {}), _) -> -- never do negative cache Nothing Just (qres, ctime) -> if diffUTCTime now ctime > ttl then Nothing else Just (open_id, qres) Nothing -> Nothing let cached_open_ids = map fst cached_results let uncached_open_ids = open_ids \\ cached_open_ids let split_inputs results xs = let (xs1, xs2) = splitAt wxppBatchQueryEndUserInfoMaxNum xs in if null xs1 then reverse results else split_inputs (xs1 : results) xs2 uncached_results <- fmap mconcat $ forM (split_inputs [] uncached_open_ids) $ \ to_query_open_ids -> do results <- wxppBatchQueryEndUserInfo atk to_query_open_ids unless (length results == length to_query_open_ids) $ do $logWarnS wxppLogSource $ "wxppBatchQueryEndUserInfo return unmatched result num: got " <> tshow (length results) <> ", but expected " <> tshow (length to_query_open_ids) return results let cached_results' = mapFromList cached_results :: Map WxppOpenID EndUserQueryResult fmap (mapFromList . catMaybes) $ forM open_ids $ \ open_id -> do case lookup open_id cached_results' of Just qres -> return $ Just (open_id, qres) Nothing -> do case lookup open_id uncached_results of Just qres -> do liftIO $ wxppCacheSaveUserInfo cache app_id qres return $ Just (open_id, qres) Nothing -> do $logWarnS wxppLogSource $ "failed to find end user info for: " <> unWxppOpenID open_id return Nothing where app_id = accessTokenApp atk data GroupBasicInfo = GroupBasicInfo WxppUserGroupID Text Int -- {{{1 instances instance FromJSON GroupBasicInfo where parseJSON = withObject "GroupBasicInfo" $ \o -> GroupBasicInfo <$> o .: "id" <*> o .: "name" <*> o .: "count" instance ToJSON GroupBasicInfo where toJSON (GroupBasicInfo group_id name cnt) = object [ "id" .= group_id , "name" .= name , "count" .= cnt ] -- }}}1 data ListGroupResult = ListGroupResult { unListGroupResult :: [GroupBasicInfo] } instance FromJSON ListGroupResult where parseJSON = withObject "ListGroupResult" $ \o -> ListGroupResult <$> o .: "groups" -- | 取所有分组的基本信息 {-# DEPRECATED wxppListUserGroups "use WxppUserTags instead" #-} wxppListUserGroups :: (WxppApiMonad env m) => AccessToken -> m [GroupBasicInfo] -- {{{1 wxppListUserGroups (AccessToken { accessTokenData = atk }) = do (sess, url_conf) <- asks (getWreqSession &&& getWxppUrlConfig) let url = wxppUrlConfSecureApiBase url_conf <> "/groups/get" opts = defaults & param "access_token" .~ [ atk ] liftIO (WS.getWith opts sess url) >>= asWxppWsResponseNormal' >>= return . unListGroupResult -- }}}1 data CreateGroupResult = CreateGroupResult WxppUserGroupID Text instance FromJSON CreateGroupResult where parseJSON = withObject "CreateGroupResult" $ \o -> do o2 <- o .: "group" CreateGroupResult <$> o2 .: "id" <*> o2 .: "name" {-# DEPRECATED wxppCreateUserGroup "use wxppCreateUserTag instead" #-} wxppCreateUserGroup :: (WxppApiMonad env m) => AccessToken -> Text -> m WxppUserGroupID wxppCreateUserGroup (AccessToken { accessTokenData = atk }) name = do (sess, url_conf) <- asks (getWreqSession &&& getWxppUrlConfig) let url = wxppUrlConfSecureApiBase url_conf <> "/groups/create" opts = defaults & param "access_token" .~ [ atk ] CreateGroupResult grp_id name' <- liftIO (WS.postWith opts sess url $ object [ "group" .= object [ "name" .= name ] ]) >>= asWxppWsResponseNormal' when (name' /= name) $ do $logErrorS wxppLogSource $ "creating user group but get different name: " <> "expecting " <> name <> ", but got " <> name' liftIO $ throwIO $ userError "unexpected group name returned" return grp_id -- | 删除一个用户分组 {-# DEPRECATED wxppDeleteUserGroup "use wxppDeleteUserTag instead" #-} wxppDeleteUserGroup :: (WxppApiMonad env m) => AccessToken -> WxppUserGroupID -> m () wxppDeleteUserGroup (AccessToken { accessTokenData = atk }) grp_id = do (sess, url_conf) <- asks (getWreqSession &&& getWxppUrlConfig) let url = wxppUrlConfSecureApiBase url_conf <> "/groups/delete" opts = defaults & param "access_token" .~ [ atk ] liftIO (WS.postWith opts sess url $ object [ "group" .= object [ "id" .= grp_id ] ]) >>= asWxppWsResponseVoid -- | 修改分组名 {-# DEPRECATED wxppRenameUserGroup "use wxppRenameUserTag instead" #-} wxppRenameUserGroup :: (WxppApiMonad env m) => AccessToken -> WxppUserGroupID -> Text -> m () wxppRenameUserGroup (AccessToken { accessTokenData = atk }) grp_id name = do (sess, url_conf) <- asks (getWreqSession &&& getWxppUrlConfig) let url = wxppUrlConfSecureApiBase url_conf <> "/groups/update" opts = defaults & param "access_token" .~ [ atk ] liftIO (WS.postWith opts sess url $ object [ "group" .= object [ "id" .= grp_id, "name" .= name ] ]) >>= asWxppWsResponseVoid data GetGroupResult = GetGroupResult WxppUserGroupID instance FromJSON GetGroupResult where parseJSON = withObject "GetGroupResult" $ \o -> do GetGroupResult <$> o .: "groupid" -- | 查询用户所在分组 {-# DEPRECATED wxppGetGroupOfUser "use wxppGetTagsOfUser instead" #-} wxppGetGroupOfUser :: (WxppApiMonad env m) => AccessToken -> WxppOpenID -> m WxppUserGroupID wxppGetGroupOfUser (AccessToken { accessTokenData = atk }) open_id = do (sess, url_conf) <- asks (getWreqSession &&& getWxppUrlConfig) let url = wxppUrlConfSecureApiBase url_conf <> "/groups/getid" opts = defaults & param "access_token" .~ [ atk ] GetGroupResult grp_id <- liftIO (WS.postWith opts sess url $ object [ "openid" .= open_id ]) >>= asWxppWsResponseNormal' return grp_id -- | 移动用户至指定分组 {-# DEPRECATED wxppSetUserGroup "use wxppUserTagging instead" #-} wxppSetUserGroup :: (WxppApiMonad env m) => AccessToken -> WxppUserGroupID -> WxppOpenID -> m () wxppSetUserGroup (AccessToken { accessTokenData = atk }) grp_id open_id = do (sess, url_conf) <- asks (getWreqSession &&& getWxppUrlConfig) let url = wxppUrlConfSecureApiBase url_conf <> "/groups/members/update" opts = defaults & param "access_token" .~ [ atk ] liftIO (WS.postWith opts sess url $ object [ "to_groupid" .= grp_id, "openid" .= open_id ]) >>= asWxppWsResponseVoid -- | 批量移动用户至指定分组 {-# DEPRECATED wxppBatchSetUserGroup "use wxppUserTagging instead" #-} wxppBatchSetUserGroup :: (WxppApiMonad env m) => AccessToken -> WxppUserGroupID -> [WxppOpenID] -> m () wxppBatchSetUserGroup (AccessToken { accessTokenData = atk }) grp_id open_id_list = do (sess, url_conf) <- asks (getWreqSession &&& getWxppUrlConfig) let url = wxppUrlConfSecureApiBase url_conf <> "/groups/members/batchupdate" opts = defaults & param "access_token" .~ [ atk ] liftIO (WS.postWith opts sess url $ object [ "to_groupid" .= grp_id, "openid_list" .= open_id_list ]) >>= asWxppWsResponseVoid -- vim: set foldmethod=marker:
yoo-e/weixin-mp-sdk
WeiXin/PublicPlatform/EndUser.hs
mit
18,373
0
27
6,009
3,910
1,987
1,923
-1
-1
{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-} {-# OPTIONS_GHC -fno-warn-unused-binds #-} {-# OPTIONS_GHC -fno-warn-unused-matches #-} -- Derived from AWS service descriptions, licensed under Apache 2.0. -- | -- Module : Network.AWS.CloudHSM.DeleteHSM -- Copyright : (c) 2013-2015 Brendan Hay -- License : Mozilla Public License, v. 2.0. -- Maintainer : Brendan Hay <[email protected]> -- Stability : auto-generated -- Portability : non-portable (GHC extensions) -- -- Deletes an HSM. Once complete, this operation cannot be undone and your -- key material cannot be recovered. -- -- /See:/ <http://docs.aws.amazon.com/cloudhsm/latest/dg/API_DeleteHSM.html AWS API Reference> for DeleteHSM. module Network.AWS.CloudHSM.DeleteHSM ( -- * Creating a Request deleteHSM , DeleteHSM -- * Request Lenses , dhHSMARN -- * Destructuring the Response , deleteHSMResponse , DeleteHSMResponse -- * Response Lenses , dhsmrsResponseStatus , dhsmrsStatus ) where import Network.AWS.CloudHSM.Types import Network.AWS.CloudHSM.Types.Product import Network.AWS.Prelude import Network.AWS.Request import Network.AWS.Response -- | Contains the inputs for the DeleteHsm action. -- -- /See:/ 'deleteHSM' smart constructor. newtype DeleteHSM = DeleteHSM' { _dhHSMARN :: Text } deriving (Eq,Read,Show,Data,Typeable,Generic) -- | Creates a value of 'DeleteHSM' with the minimum fields required to make a request. -- -- Use one of the following lenses to modify other fields as desired: -- -- * 'dhHSMARN' deleteHSM :: Text -- ^ 'dhHSMARN' -> DeleteHSM deleteHSM pHSMARN_ = DeleteHSM' { _dhHSMARN = pHSMARN_ } -- | The ARN of the HSM to delete. dhHSMARN :: Lens' DeleteHSM Text dhHSMARN = lens _dhHSMARN (\ s a -> s{_dhHSMARN = a}); instance AWSRequest DeleteHSM where type Rs DeleteHSM = DeleteHSMResponse request = postJSON cloudHSM response = receiveJSON (\ s h x -> DeleteHSMResponse' <$> (pure (fromEnum s)) <*> (x .:> "Status")) instance ToHeaders DeleteHSM where toHeaders = const (mconcat ["X-Amz-Target" =# ("CloudHsmFrontendService.DeleteHsm" :: ByteString), "Content-Type" =# ("application/x-amz-json-1.1" :: ByteString)]) instance ToJSON DeleteHSM where toJSON DeleteHSM'{..} = object (catMaybes [Just ("HsmArn" .= _dhHSMARN)]) instance ToPath DeleteHSM where toPath = const "/" instance ToQuery DeleteHSM where toQuery = const mempty -- | Contains the output of the DeleteHsm action. -- -- /See:/ 'deleteHSMResponse' smart constructor. data DeleteHSMResponse = DeleteHSMResponse' { _dhsmrsResponseStatus :: !Int , _dhsmrsStatus :: !Text } deriving (Eq,Read,Show,Data,Typeable,Generic) -- | Creates a value of 'DeleteHSMResponse' with the minimum fields required to make a request. -- -- Use one of the following lenses to modify other fields as desired: -- -- * 'dhsmrsResponseStatus' -- -- * 'dhsmrsStatus' deleteHSMResponse :: Int -- ^ 'dhsmrsResponseStatus' -> Text -- ^ 'dhsmrsStatus' -> DeleteHSMResponse deleteHSMResponse pResponseStatus_ pStatus_ = DeleteHSMResponse' { _dhsmrsResponseStatus = pResponseStatus_ , _dhsmrsStatus = pStatus_ } -- | The response status code. dhsmrsResponseStatus :: Lens' DeleteHSMResponse Int dhsmrsResponseStatus = lens _dhsmrsResponseStatus (\ s a -> s{_dhsmrsResponseStatus = a}); -- | The status of the action. dhsmrsStatus :: Lens' DeleteHSMResponse Text dhsmrsStatus = lens _dhsmrsStatus (\ s a -> s{_dhsmrsStatus = a});
fmapfmapfmap/amazonka
amazonka-cloudhsm/gen/Network/AWS/CloudHSM/DeleteHSM.hs
mpl-2.0
3,972
0
14
926
578
347
231
76
1
module GramLab.Morfette.Models2 ( train , trainFun , predict , predictPipeline , toModelFun , mkPreprune , sentToExamples , FeatureSpec (..) , Row(..) ) where import GramLab.Morfette.LZipper import qualified Data.Map as Map import Data.Map ((!)) import Data.List (sortBy,foldl',transpose) import Data.Ord (comparing) import Data.Dynamic import GramLab.FeatureSet import qualified GramLab.Perceptron.Model as M import Data.Traversable (forM) import qualified Data.IntMap as IntMap import Data.Maybe (fromMaybe) import Debug.Trace import Data.Binary import Control.Monad (liftM, liftM2) import GramLab.Utils (uniq) import qualified Data.Vector.Unboxed as U import GramLab.Morfette.BinaryInstances data Row t a = Row { input :: !t, output :: ![a] } deriving (Eq,Ord,Show,Read) data FeatureSpec t a = FS { label :: Row t a -> a , features :: LZipper (Row t a) (Row t a) (Row t a) -> [Feature String Double] , preprune :: ProbDist a -> ProbDist a , check :: LZipper (Row t a) (Row t a) (Row t a) -> a -> Bool , pruneUniqLabels :: Bool , trainSettings :: M.TrainSettings } instance (Binary t, Binary a) => Binary (Row t a) where put t = put (input t) >> put (output t) get = liftM2 Row get get type ProbDist a = [(a,Double)] type Model t a = LZipper (Row t a) (Row t a) (Row t a) -> ProbDist a beamSearch :: Int -- beam size -> [Model t a] -- models for each output column -> ProbDist (LZipper (Row t a) (Row t a) (Row t a)) -- prob dist over sequence of "tokens in context" (as lzippers) -> ProbDist [Row t a] -- prob dist over sequences of "tokens" beamSearch n ms pzs = let apply pzs model = prune n [ (modify (\t -> t { output = output t ++ [label] }) z -- add label to output , p0 * p -- multiply probability in ) | (z, p0) <- pzs -- for each sequence (lzipper) , (label, p) <- model z -- get label and prob by applying -- model. ] in if any (atEnd . fst) pzs -- of any lzipper at end then return tokens then flip map pzs $ \(z,p) -> (reverse (left z), p) else -- otherwise apply both classifiers in turn in the lzipper seq, -- prune, adjust probs beamSearch n ms . map (\(z,p) -> (slide z,p)) $! (foldl' apply pzs ms) -- pruning and prepruning prune :: Int -> ProbDist a -> ProbDist a prune n = take n . sortBy (flip (comparing snd)) collectUntil cond f z [] = [] collectUntil cond f z (x:xs) = let z' = (f $! x) $! z in if cond x z' then [] else x: collectUntil cond f z' xs mkPreprune th = collectUntil (\x z -> th > snd x / z) ((+) . snd) 0 trainFun :: (Ord a, Show a) => [FeatureSpec t a] -> [[Row t a]] -> [Model t a] trainFun fspecs sents = let ms = train fspecs sents in (zipWith toModelFun fspecs ms) train :: (Ord a,Show a) => [FeatureSpec t a] -> [[Row t a]] -> [M.Model a Int String Double] train fspecs sents = flip map fspecs $ \fs -> let yxs_all = concatMap (sentToExamples fs) $ sents zs_all = concat [ take (length s) . iterate slide . fromList $ s | s <- sents ] ys = (if pruneUniqLabels fs then Map.filter (>1) else id) . Map.fromListWith (+) . map (\ (y, _) -> (y, 1)) $ yxs_all (yxs, zs) = unzip . filter (flip Map.member ys . fst . fst) $ zip yxs_all zs_all yss = [ [ y | y <- Map.keys ys , check fs z y ] | z <- zs ] in M.train (trainSettings fs) yss yxs toModelFun :: (Ord a, Show a) => FeatureSpec t a -> (M.Model a Int String Double) -> Model t a toModelFun fs m = let ys = Map.keys . M.classMap . M.modelData $ m in \ z -> case filter (check fs z) ys of [] -> error "GramLab.Morfette.Models.toModelFun: unexpected []" y:ys' -> preprune fs . M.distribution m (y:ys') . features fs $ z predict :: Int -> Int -> [Model t a] -> [[Row t a]] -> [[[Row t a]]] predict k beamSize models sents = map predictK sents where predictK s = transpose . map fst . take k . beamSearch beamSize models $ [(fromList s,1)] predictPipeline :: Int -> [Model t a] -> [[Row t a]] -> [[Row t a]] predictPipeline beamSize models sents = map predictK sents where predictK s = foldl' (\s1 m -> fst . head . beamSearch beamSize [m] $ [(fromList s1,1)]) s models sentToExamples :: FeatureSpec t a -> [Row t a] -> [(a,[Feature String Double])] sentToExamples fs xs = slideThru f (fromList xs) where f z = ( label fs . fromMaybe (error "GramLab.Morfette.Models.sentToExample:fromMaybe") . focus $ z , features fs z) slideThru f z | atEnd z = [] slideThru f z = f z:slideThru f (slide z)
bitemyapp/morfette
src/GramLab/Morfette/Models2.hs
bsd-2-clause
6,189
0
18
2,730
1,990
1,056
934
129
2
{- (c) The University of Glasgow 2006 (c) The GRASP/AQUA Project, Glasgow University, 1992-1999 Analysis functions over data types. Specficially, detecting recursive types. This stuff is only used for source-code decls; it's recorded in interface files for imported data types. -} {-# LANGUAGE CPP #-} module TcTyDecls( calcRecFlags, RecTyInfo(..), calcSynCycles, checkClassCycles, -- * Roles RoleAnnots, extractRoleAnnots, emptyRoleAnnots, lookupRoleAnnots, -- * Implicits tcAddImplicits, -- * Record selectors mkRecSelBinds, mkOneRecordSelector ) where #include "HsVersions.h" import TcRnMonad import TcEnv import TcBinds( tcRecSelBinds ) import TyCoRep( Type(..), TyBinder(..), delBinderVar ) import TcType import TysWiredIn( unitTy ) import MkCore( rEC_SEL_ERROR_ID ) import HsSyn import Class import Type import HscTypes import TyCon import ConLike import DataCon import Name import NameEnv import RdrName ( mkVarUnqual ) import Id import IdInfo import VarEnv import VarSet import NameSet import Coercion ( ltRole ) import Digraph import BasicTypes import SrcLoc import Unique ( mkBuiltinUnique ) import Outputable import Util import Maybes import Data.List import Bag import FastString import Control.Monad {- ************************************************************************ * * Cycles in type synonym declarations * * ************************************************************************ Checking for class-decl loops is easy, because we don't allow class decls in interface files. We allow type synonyms in hi-boot files, but we *trust* hi-boot files, so we don't check for loops that involve them. So we only look for synonym loops in the module being compiled. We check for type synonym and class cycles on the *source* code. Main reasons: a) Otherwise we'd need a special function to extract type-synonym tycons from a type, whereas we already have the free vars pinned on the decl b) If we checked for type synonym loops after building the TyCon, we can't do a hoistForAllTys on the type synonym rhs, (else we fall into a black hole) which seems unclean. Apart from anything else, it'd mean that a type-synonym rhs could have for-alls to the right of an arrow, which means adding new cases to the validity checker Indeed, in general, checking for cycles beforehand means we need to be less careful about black holes through synonym cycles. The main disadvantage is that a cycle that goes via a type synonym in an .hi-boot file can lead the compiler into a loop, because it assumes that cycles only occur entirely within the source code of the module being compiled. But hi-boot files are trusted anyway, so this isn't much worse than (say) a kind error. [ NOTE ---------------------------------------------- If we reverse this decision, this comment came from tcTyDecl1, and should go back there -- dsHsType, not tcHsKindedType, to avoid a loop. tcHsKindedType does hoisting, -- which requires looking through synonyms... and therefore goes into a loop -- on (erroneously) recursive synonyms. -- Solution: do not hoist synonyms, because they'll be hoisted soon enough -- when they are substituted We'd also need to add back in this definition synonymTyConsOfType :: Type -> [TyCon] -- Does not look through type synonyms at all -- Return a list of synonym tycons synonymTyConsOfType ty = nameEnvElts (go ty) where go :: Type -> NameEnv TyCon -- The NameEnv does duplicate elim go (TyVarTy v) = emptyNameEnv go (TyConApp tc tys) = go_tc tc tys go (AppTy a b) = go a `plusNameEnv` go b go (FunTy a b) = go a `plusNameEnv` go b go (ForAllTy _ ty) = go ty go_tc tc tys | isTypeSynonymTyCon tc = extendNameEnv (go_s tys) (tyConName tc) tc | otherwise = go_s tys go_s tys = foldr (plusNameEnv . go) emptyNameEnv tys ---------------------------------------- END NOTE ] -} mkSynEdges :: [LTyClDecl Name] -> [(LTyClDecl Name, Name, [Name])] mkSynEdges syn_decls = [ (ldecl, name, nameSetElems fvs) | ldecl@(L _ (SynDecl { tcdLName = L _ name , tcdFVs = fvs })) <- syn_decls ] calcSynCycles :: [LTyClDecl Name] -> [SCC (LTyClDecl Name)] calcSynCycles = stronglyConnCompFromEdgedVertices . mkSynEdges {- Note [Superclass cycle check] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The superclass cycle check for C decides if we can statically guarantee that expanding C's superclass cycles transitively is guaranteed to terminate. This is a Haskell98 requirement, but one that we lift with -XUndecidableSuperClasses. The worry is that a superclass cycle could make the type checker loop. More precisely, with a constraint (Given or Wanted) C ty1 .. tyn one approach is to instantiate all of C's superclasses, transitively. We can only do so if that set is finite. This potential loop occurs only through superclasses. This, for exmaple, is fine class C a where op :: C b => a -> b -> b even though C's full definition uses C. Making the check static also makes it conservative. Eg type family F a class F a => C a Here an instance of (F a) might mention C: type instance F [a] = C a and now we'd have a loop. The static check works like this, starting with C * Look at C's superclass predicates * If any is a type-function application, or is headed by a type variable, fail * If any has C at the head, fail * If any has a type class D at the head, make the same test with D A tricky point is: what if there is a type variable at the head? Consider this: class f (C f) => C f class c => Id c and now expand superclasses for constraint (C Id): C Id --> Id (C Id) --> C Id --> .... Each step expands superclasses one layer, and clearly does not terminate. -} checkClassCycles :: Class -> Maybe SDoc -- Nothing <=> ok -- Just err <=> possible cycle error checkClassCycles cls = do { (definite_cycle, err) <- go (unitNameSet (getName cls)) cls (mkTyVarTys (classTyVars cls)) ; let herald | definite_cycle = text "Superclass cycle for" | otherwise = text "Potential superclass cycle for" ; return (vcat [ herald <+> quotes (ppr cls) , nest 2 err, hint]) } where hint = text "Use UndecidableSuperClasses to accept this" -- Expand superclasses starting with (C a b), complaining -- if you find the same class a second time, or a type function -- or predicate headed by a type variable -- -- NB: this code duplicates TcType.transSuperClasses, but -- with more error message generation clobber -- Make sure the two stay in sync. go :: NameSet -> Class -> [Type] -> Maybe (Bool, SDoc) go so_far cls tys = firstJusts $ map (go_pred so_far) $ immSuperClasses cls tys go_pred :: NameSet -> PredType -> Maybe (Bool, SDoc) -- Nothing <=> ok -- Just (True, err) <=> definite cycle -- Just (False, err) <=> possible cycle go_pred so_far pred -- NB: tcSplitTyConApp looks through synonyms | Just (tc, tys) <- tcSplitTyConApp_maybe pred = go_tc so_far pred tc tys | hasTyVarHead pred = Just (False, hang (text "one of whose superclass constraints is headed by a type variable:") 2 (quotes (ppr pred))) | otherwise = Nothing go_tc :: NameSet -> PredType -> TyCon -> [Type] -> Maybe (Bool, SDoc) go_tc so_far pred tc tys | isFamilyTyCon tc = Just (False, hang (text "one of whose superclass constraints is headed by a type family:") 2 (quotes (ppr pred))) | Just cls <- tyConClass_maybe tc = go_cls so_far cls tys | otherwise -- Equality predicate, for example = Nothing go_cls :: NameSet -> Class -> [Type] -> Maybe (Bool, SDoc) go_cls so_far cls tys | cls_nm `elemNameSet` so_far = Just (True, text "one of whose superclasses is" <+> quotes (ppr cls)) | isCTupleClass cls = go so_far cls tys | otherwise = do { (b,err) <- go (so_far `extendNameSet` cls_nm) cls tys ; return (b, text "one of whose superclasses is" <+> quotes (ppr cls) $$ err) } where cls_nm = getName cls {- ************************************************************************ * * Deciding which type constructors are recursive * * ************************************************************************ Identification of recursive TyCons ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The knot-tying parameters: @rec_details_list@ is an alist mapping @Name@s to @TyThing@s. Identifying a TyCon as recursive serves two purposes 1. Avoid infinite types. Non-recursive newtypes are treated as "transparent", like type synonyms, after the type checker. If we did this for all newtypes, we'd get infinite types. So we figure out for each newtype whether it is "recursive", and add a coercion if so. In effect, we are trying to "cut the loops" by identifying a loop-breaker. 2. Avoid infinite unboxing. This has nothing to do with newtypes. Suppose we have data T = MkT Int T f (MkT x t) = f t Well, this function diverges, but we don't want the strictness analyser to diverge. But the strictness analyser will diverge because it looks deeper and deeper into the structure of T. (I believe there are examples where the function does something sane, and the strictness analyser still diverges, but I can't see one now.) Now, concerning (1), the FC2 branch currently adds a coercion for ALL newtypes. I did this as an experiment, to try to expose cases in which the coercions got in the way of optimisations. If it turns out that we can indeed always use a coercion, then we don't risk recursive types, and don't need to figure out what the loop breakers are. For newtype *families* though, we will always have a coercion, so they are always loop breakers! So you can easily adjust the current algorithm by simply treating all newtype families as loop breakers (and indeed type families). I think. For newtypes, we label some as "recursive" such that INVARIANT: there is no cycle of non-recursive newtypes In any loop, only one newtype need be marked as recursive; it is a "loop breaker". Labelling more than necessary as recursive is OK, provided the invariant is maintained. A newtype M.T is defined to be "recursive" iff (a) it is declared in an hi-boot file (see RdrHsSyn.hsIfaceDecl) (b) it is declared in a source file, but that source file has a companion hi-boot file which declares the type or (c) one can get from T's rhs to T via type synonyms, or non-recursive newtypes *in M* e.g. newtype T = MkT (T -> Int) (a) is conservative; declarations in hi-boot files are always made loop breakers. That's why in (b) we can restrict attention to tycons in M, because any loops through newtypes outside M will be broken by those newtypes (b) ensures that a newtype is not treated as a loop breaker in one place and later as a non-loop-breaker. This matters in GHCi particularly, when a newtype T might be embedded in many types in the environment, and then T's source module is compiled. We don't want T's recursiveness to change. The "recursive" flag for algebraic data types is irrelevant (never consulted) for types with more than one constructor. An algebraic data type M.T is "recursive" iff it has just one constructor, and (a) it is declared in an hi-boot file (see RdrHsSyn.hsIfaceDecl) (b) it is declared in a source file, but that source file has a companion hi-boot file which declares the type or (c) one can get from its arg types to T via type synonyms, or by non-recursive newtypes or non-recursive product types in M e.g. data T = MkT (T -> Int) Bool Just like newtype in fact A type synonym is recursive if one can get from its right hand side back to it via type synonyms. (This is reported as an error.) A class is recursive if one can get from its superclasses back to it. (This is an error too.) Hi-boot types ~~~~~~~~~~~~~ A data type read from an hi-boot file will have an AbstractTyCon as its AlgTyConRhs and will respond True to isAbstractTyCon. The idea is that we treat these as if one could get from these types to anywhere. So when we see module Baz where import {-# SOURCE #-} Foo( T ) newtype S = MkS T then we mark S as recursive, just in case. What that means is that if we see import Baz( S ) newtype R = MkR S then we don't need to look inside S to compute R's recursiveness. Since S is imported (not from an hi-boot file), one cannot get from R back to S except via an hi-boot file, and that means that some data type will be marked recursive along the way. So R is unconditionly non-recursive (i.e. there'll be a loop breaker elsewhere if necessary) This in turn means that we grovel through fewer interface files when computing recursiveness, because we need only look at the type decls in the module being compiled, plus the outer structure of directly-mentioned types. -} data RecTyInfo = RTI { rti_roles :: Name -> [Role] , rti_is_rec :: Name -> RecFlag } calcRecFlags :: SelfBootInfo -> Bool -- hs-boot file? -> RoleAnnots -> [TyCon] -> RecTyInfo -- The 'boot_names' are the things declared in M.hi-boot, if M is the current module. -- Any type constructors in boot_names are automatically considered loop breakers -- Recursion of newtypes/data types can happen via -- the class TyCon, so all_tycons includes the class tycons calcRecFlags boot_details is_boot mrole_env all_tycons = RTI { rti_roles = roles , rti_is_rec = is_rec } where roles = inferRoles is_boot mrole_env all_tycons ----------------- Recursion calculation ---------------- is_rec n | n `elemNameSet` rec_names = Recursive | otherwise = NonRecursive boot_name_set = case boot_details of NoSelfBoot -> emptyNameSet SelfBoot { sb_tcs = tcs } -> tcs rec_names = boot_name_set `unionNameSet` nt_loop_breakers `unionNameSet` prod_loop_breakers ------------------------------------------------- -- NOTE -- These edge-construction loops rely on -- every loop going via tyclss, the types and classes -- in the module being compiled. Stuff in interface -- files should be correctly marked. If not (e.g. a -- type synonym in a hi-boot file) we can get an infinite -- loop. We could program round this, but it'd make the code -- rather less nice, so I'm not going to do that yet. single_con_tycons = [ tc | tc <- all_tycons , not (tyConName tc `elemNameSet` boot_name_set) -- Remove the boot_name_set because they are -- going to be loop breakers regardless. , isSingleton (tyConDataCons tc) ] -- Both newtypes and data types, with exactly one data constructor (new_tycons, prod_tycons) = partition isNewTyCon single_con_tycons -- NB: we do *not* call isProductTyCon because that checks -- for vanilla-ness of data constructors; and that depends -- on empty existential type variables; and that is figured -- out by tcResultType; which uses tcMatchTy; which uses -- coreView; which calls expandSynTyCon_maybe; which uses -- the recursiveness of the TyCon. Result... a black hole. -- YUK YUK YUK --------------- Newtypes ---------------------- nt_loop_breakers = mkNameSet (findLoopBreakers nt_edges) is_rec_nt tc = tyConName tc `elemNameSet` nt_loop_breakers -- is_rec_nt is a locally-used helper function nt_edges = [(t, mk_nt_edges t) | t <- new_tycons] mk_nt_edges nt -- Invariant: nt is a newtype = [ tc | tc <- nameEnvElts (tyConsOfType (new_tc_rhs nt)) -- tyConsOfType looks through synonyms , tc `elem` new_tycons ] -- If not (tc `elem` new_tycons) we know that either it's a local *data* type, -- or it's imported. Either way, it can't form part of a newtype cycle --------------- Product types ---------------------- prod_loop_breakers = mkNameSet (findLoopBreakers prod_edges) prod_edges = [(tc, mk_prod_edges tc) | tc <- prod_tycons] mk_prod_edges tc -- Invariant: tc is a product tycon = concatMap (mk_prod_edges1 tc) (dataConOrigArgTys (head (tyConDataCons tc))) mk_prod_edges1 ptc ty = concatMap (mk_prod_edges2 ptc) (nameEnvElts (tyConsOfType ty)) mk_prod_edges2 ptc tc | tc `elem` prod_tycons = [tc] -- Local product | tc `elem` new_tycons = if is_rec_nt tc -- Local newtype then [] else mk_prod_edges1 ptc (new_tc_rhs tc) -- At this point we know that either it's a local non-product data type, -- or it's imported. Either way, it can't form part of a cycle | otherwise = [] new_tc_rhs :: TyCon -> Type new_tc_rhs tc = snd (newTyConRhs tc) -- Ignore the type variables findLoopBreakers :: [(TyCon, [TyCon])] -> [Name] -- Finds a set of tycons that cut all loops findLoopBreakers deps = go [(tc,tc,ds) | (tc,ds) <- deps] where go edges = [ name | CyclicSCC ((tc,_,_) : edges') <- stronglyConnCompFromEdgedVerticesR edges, name <- tyConName tc : go edges'] {- ************************************************************************ * * Role annotations * * ************************************************************************ -} type RoleAnnots = NameEnv (LRoleAnnotDecl Name) extractRoleAnnots :: TyClGroup Name -> RoleAnnots extractRoleAnnots (TyClGroup { group_roles = roles }) = mkNameEnv [ (tycon, role_annot) | role_annot@(L _ (RoleAnnotDecl (L _ tycon) _)) <- roles ] emptyRoleAnnots :: RoleAnnots emptyRoleAnnots = emptyNameEnv lookupRoleAnnots :: RoleAnnots -> Name -> Maybe (LRoleAnnotDecl Name) lookupRoleAnnots = lookupNameEnv {- ************************************************************************ * * Role inference * * ************************************************************************ Note [Role inference] ~~~~~~~~~~~~~~~~~~~~~ The role inference algorithm datatype definitions to infer the roles on the parameters. Although these roles are stored in the tycons, we can perform this algorithm on the built tycons, as long as we don't peek at an as-yet-unknown roles field! Ah, the magic of laziness. First, we choose appropriate initial roles. For families and classes, roles (including initial roles) are N. For datatypes, we start with the role in the role annotation (if any), or otherwise use Phantom. This is done in initialRoleEnv1. The function irGroup then propagates role information until it reaches a fixpoint, preferring N over (R or P) and R over P. To aid in this, we have a monad RoleM, which is a combination reader and state monad. In its state are the current RoleEnv, which gets updated by role propagation, and an update bit, which we use to know whether or not we've reached the fixpoint. The environment of RoleM contains the tycon whose parameters we are inferring, and a VarEnv from parameters to their positions, so we can update the RoleEnv. Between tycons, this reader information is missing; it is added by addRoleInferenceInfo. There are two kinds of tycons to consider: algebraic ones (excluding classes) and type synonyms. (Remember, families don't participate -- all their parameters are N.) An algebraic tycon processes each of its datacons, in turn. Note that a datacon's universally quantified parameters might be different from the parent tycon's parameters, so we use the datacon's univ parameters in the mapping from vars to positions. Note also that we don't want to infer roles for existentials (they're all at N, too), so we put them in the set of local variables. As an optimisation, we skip any tycons whose roles are already all Nominal, as there nowhere else for them to go. For synonyms, we just analyse their right-hand sides. irType walks through a type, looking for uses of a variable of interest and propagating role information. Because anything used under a phantom position is at phantom and anything used under a nominal position is at nominal, the irType function can assume that anything it sees is at representational. (The other possibilities are pruned when they're encountered.) The rest of the code is just plumbing. How do we know that this algorithm is correct? It should meet the following specification: Let Z be a role context -- a mapping from variables to roles. The following rules define the property (Z |- t : r), where t is a type and r is a role: Z(a) = r' r' <= r ------------------------- RCVar Z |- a : r ---------- RCConst Z |- T : r -- T is a type constructor Z |- t1 : r Z |- t2 : N -------------- RCApp Z |- t1 t2 : r forall i<=n. (r_i is R or N) implies Z |- t_i : r_i roles(T) = r_1 .. r_n ---------------------------------------------------- RCDApp Z |- T t_1 .. t_n : R Z, a:N |- t : r ---------------------- RCAll Z |- forall a:k.t : r We also have the following rules: For all datacon_i in type T, where a_1 .. a_n are universally quantified and b_1 .. b_m are existentially quantified, and the arguments are t_1 .. t_p, then if forall j<=p, a_1 : r_1 .. a_n : r_n, b_1 : N .. b_m : N |- t_j : R, then roles(T) = r_1 .. r_n roles(->) = R, R roles(~#) = N, N With -dcore-lint on, the output of this algorithm is checked in checkValidRoles, called from checkValidTycon. Note [Role-checking data constructor arguments] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider data T a where MkT :: Eq b => F a -> (a->a) -> T (G a) Then we want to check the roles at which 'a' is used in MkT's type. We want to work on the user-written type, so we need to take into account * the arguments: (F a) and (a->a) * the context: C a b * the result type: (G a) -- this is in the eq_spec Note [Coercions in role inference] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Is (t |> co1) representationally equal to (t |> co2)? Of course they are! Changing the kind of a type is totally irrelevant to the representation of that type. So, we want to totally ignore coercions when doing role inference. This includes omitting any type variables that appear in nominal positions but only within coercions. -} type RoleEnv = NameEnv [Role] -- from tycon names to roles -- This, and any of the functions it calls, must *not* look at the roles -- field of a tycon we are inferring roles about! -- See Note [Role inference] inferRoles :: Bool -> RoleAnnots -> [TyCon] -> Name -> [Role] inferRoles is_boot annots tycons = let role_env = initialRoleEnv is_boot annots tycons role_env' = irGroup role_env tycons in \name -> case lookupNameEnv role_env' name of Just roles -> roles Nothing -> pprPanic "inferRoles" (ppr name) initialRoleEnv :: Bool -> RoleAnnots -> [TyCon] -> RoleEnv initialRoleEnv is_boot annots = extendNameEnvList emptyNameEnv . map (initialRoleEnv1 is_boot annots) initialRoleEnv1 :: Bool -> RoleAnnots -> TyCon -> (Name, [Role]) initialRoleEnv1 is_boot annots_env tc | isFamilyTyCon tc = (name, map (const Nominal) bndrs) | isAlgTyCon tc = (name, default_roles) | isTypeSynonymTyCon tc = (name, default_roles) | otherwise = pprPanic "initialRoleEnv1" (ppr tc) where name = tyConName tc bndrs = tyConBinders tc visflags = map binderVisibility $ take (tyConArity tc) bndrs num_exps = count (== Visible) visflags -- if the number of annotations in the role annotation decl -- is wrong, just ignore it. We check this in the validity check. role_annots = case lookupNameEnv annots_env name of Just (L _ (RoleAnnotDecl _ annots)) | annots `lengthIs` num_exps -> map unLoc annots _ -> replicate num_exps Nothing default_roles = build_default_roles visflags role_annots build_default_roles (Visible : viss) (m_annot : ras) = (m_annot `orElse` default_role) : build_default_roles viss ras build_default_roles (_inv : viss) ras = Nominal : build_default_roles viss ras build_default_roles [] [] = [] build_default_roles _ _ = pprPanic "initialRoleEnv1 (2)" (vcat [ppr tc, ppr role_annots]) default_role | isClassTyCon tc = Nominal | is_boot && isAbstractTyCon tc = Representational | otherwise = Phantom irGroup :: RoleEnv -> [TyCon] -> RoleEnv irGroup env tcs = let (env', update) = runRoleM env $ mapM_ irTyCon tcs in if update then irGroup env' tcs else env' irTyCon :: TyCon -> RoleM () irTyCon tc | isAlgTyCon tc = do { old_roles <- lookupRoles tc ; unless (all (== Nominal) old_roles) $ -- also catches data families, -- which don't want or need role inference irTcTyVars tc $ do { mapM_ (irType emptyVarSet) (tyConStupidTheta tc) -- See #8958 ; whenIsJust (tyConClass_maybe tc) irClass ; mapM_ irDataCon (visibleDataCons $ algTyConRhs tc) }} | Just ty <- synTyConRhs_maybe tc = irTcTyVars tc $ irType emptyVarSet ty | otherwise = return () -- any type variable used in an associated type must be Nominal irClass :: Class -> RoleM () irClass cls = mapM_ ir_at (classATs cls) where cls_tvs = classTyVars cls cls_tv_set = mkVarSet cls_tvs ir_at at_tc = mapM_ (updateRole Nominal) (varSetElems nvars) where nvars = (mkVarSet $ tyConTyVars at_tc) `intersectVarSet` cls_tv_set -- See Note [Role inference] irDataCon :: DataCon -> RoleM () irDataCon datacon = setRoleInferenceVars univ_tvs $ irExTyVars ex_tvs $ \ ex_var_set -> mapM_ (irType ex_var_set) (map tyVarKind ex_tvs ++ eqSpecPreds eq_spec ++ theta ++ arg_tys) -- See Note [Role-checking data constructor arguments] where (univ_tvs, ex_tvs, eq_spec, theta, arg_tys, _res_ty) = dataConFullSig datacon irType :: VarSet -> Type -> RoleM () irType = go where go lcls (TyVarTy tv) = unless (tv `elemVarSet` lcls) $ updateRole Representational tv go lcls (AppTy t1 t2) = go lcls t1 >> markNominal lcls t2 go lcls (TyConApp tc tys) = do { roles <- lookupRolesX tc ; zipWithM_ (go_app lcls) roles tys } go lcls (ForAllTy (Named tv _) ty) = let lcls' = extendVarSet lcls tv in markNominal lcls (tyVarKind tv) >> go lcls' ty go lcls (ForAllTy (Anon arg) res) = go lcls arg >> go lcls res go _ (LitTy {}) = return () -- See Note [Coercions in role inference] go lcls (CastTy ty _) = go lcls ty go _ (CoercionTy _) = return () go_app _ Phantom _ = return () -- nothing to do here go_app lcls Nominal ty = markNominal lcls ty -- all vars below here are N go_app lcls Representational ty = go lcls ty irTcTyVars :: TyCon -> RoleM a -> RoleM a irTcTyVars tc thing = setRoleInferenceTc (tyConName tc) $ go (tyConTyVars tc) where go [] = thing go (tv:tvs) = do { markNominal emptyVarSet (tyVarKind tv) ; addRoleInferenceVar tv $ go tvs } irExTyVars :: [TyVar] -> (TyVarSet -> RoleM a) -> RoleM a irExTyVars orig_tvs thing = go emptyVarSet orig_tvs where go lcls [] = thing lcls go lcls (tv:tvs) = do { markNominal lcls (tyVarKind tv) ; go (extendVarSet lcls tv) tvs } markNominal :: TyVarSet -- local variables -> Type -> RoleM () markNominal lcls ty = let nvars = get_ty_vars ty `minusVarSet` lcls in mapM_ (updateRole Nominal) (varSetElems nvars) where -- get_ty_vars gets all the tyvars (no covars!) from a type *without* -- recurring into coercions. Recall: coercions are totally ignored during -- role inference. See [Coercions in role inference] get_ty_vars (TyVarTy tv) = unitVarSet tv get_ty_vars (AppTy t1 t2) = get_ty_vars t1 `unionVarSet` get_ty_vars t2 get_ty_vars (TyConApp _ tys) = foldr (unionVarSet . get_ty_vars) emptyVarSet tys get_ty_vars (ForAllTy bndr ty) = get_ty_vars ty `delBinderVar` bndr `unionVarSet` (tyCoVarsOfType $ binderType bndr) get_ty_vars (LitTy {}) = emptyVarSet get_ty_vars (CastTy ty _) = get_ty_vars ty get_ty_vars (CoercionTy _) = emptyVarSet -- like lookupRoles, but with Nominal tags at the end for oversaturated TyConApps lookupRolesX :: TyCon -> RoleM [Role] lookupRolesX tc = do { roles <- lookupRoles tc ; return $ roles ++ repeat Nominal } -- gets the roles either from the environment or the tycon lookupRoles :: TyCon -> RoleM [Role] lookupRoles tc = do { env <- getRoleEnv ; case lookupNameEnv env (tyConName tc) of Just roles -> return roles Nothing -> return $ tyConRoles tc } -- tries to update a role; won't ever update a role "downwards" updateRole :: Role -> TyVar -> RoleM () updateRole role tv = do { var_ns <- getVarNs ; name <- getTyConName ; case lookupVarEnv var_ns tv of Nothing -> pprPanic "updateRole" (ppr name $$ ppr tv $$ ppr var_ns) Just n -> updateRoleEnv name n role } -- the state in the RoleM monad data RoleInferenceState = RIS { role_env :: RoleEnv , update :: Bool } -- the environment in the RoleM monad type VarPositions = VarEnv Int -- See [Role inference] newtype RoleM a = RM { unRM :: Maybe Name -- of the tycon -> VarPositions -> Int -- size of VarPositions -> RoleInferenceState -> (a, RoleInferenceState) } instance Functor RoleM where fmap = liftM instance Applicative RoleM where pure x = RM $ \_ _ _ state -> (x, state) (<*>) = ap instance Monad RoleM where a >>= f = RM $ \m_info vps nvps state -> let (a', state') = unRM a m_info vps nvps state in unRM (f a') m_info vps nvps state' runRoleM :: RoleEnv -> RoleM () -> (RoleEnv, Bool) runRoleM env thing = (env', update) where RIS { role_env = env', update = update } = snd $ unRM thing Nothing emptyVarEnv 0 state state = RIS { role_env = env , update = False } setRoleInferenceTc :: Name -> RoleM a -> RoleM a setRoleInferenceTc name thing = RM $ \m_name vps nvps state -> ASSERT( isNothing m_name ) ASSERT( isEmptyVarEnv vps ) ASSERT( nvps == 0 ) unRM thing (Just name) vps nvps state addRoleInferenceVar :: TyVar -> RoleM a -> RoleM a addRoleInferenceVar tv thing = RM $ \m_name vps nvps state -> ASSERT( isJust m_name ) unRM thing m_name (extendVarEnv vps tv nvps) (nvps+1) state setRoleInferenceVars :: [TyVar] -> RoleM a -> RoleM a setRoleInferenceVars tvs thing = RM $ \m_name _vps _nvps state -> ASSERT( isJust m_name ) unRM thing m_name (mkVarEnv (zip tvs [0..])) (panic "setRoleInferenceVars") state getRoleEnv :: RoleM RoleEnv getRoleEnv = RM $ \_ _ _ state@(RIS { role_env = env }) -> (env, state) getVarNs :: RoleM VarPositions getVarNs = RM $ \_ vps _ state -> (vps, state) getTyConName :: RoleM Name getTyConName = RM $ \m_name _ _ state -> case m_name of Nothing -> panic "getTyConName" Just name -> (name, state) updateRoleEnv :: Name -> Int -> Role -> RoleM () updateRoleEnv name n role = RM $ \_ _ _ state@(RIS { role_env = role_env }) -> ((), case lookupNameEnv role_env name of Nothing -> pprPanic "updateRoleEnv" (ppr name) Just roles -> let (before, old_role : after) = splitAt n roles in if role `ltRole` old_role then let roles' = before ++ role : after role_env' = extendNameEnv role_env name roles' in RIS { role_env = role_env', update = True } else state ) {- ********************************************************************* * * Building implicits * * ********************************************************************* -} tcAddImplicits :: [TyCon] -> TcM TcGblEnv -- Given a [TyCon], add to the TcGblEnv -- * extend the TypeEnv with their implicitTyThings -- * extend the TypeEnv with any default method Ids -- * add bindings for record selectors -- * add bindings for type representations for the TyThings tcAddImplicits tycons = discardWarnings $ tcExtendGlobalEnvImplicit implicit_things $ tcExtendGlobalValEnv def_meth_ids $ do { traceTc "tcAddImplicits" $ vcat [ text "tycons" <+> ppr tycons , text "implicits" <+> ppr implicit_things ] ; tcRecSelBinds (mkRecSelBinds tycons) } where implicit_things = concatMap implicitTyConThings tycons def_meth_ids = mkDefaultMethodIds tycons mkDefaultMethodIds :: [TyCon] -> [Id] -- We want to put the default-method Ids (both vanilla and generic) -- into the type environment so that they are found when we typecheck -- the filled-in default methods of each instance declaration -- See Note [Default method Ids and Template Haskell] mkDefaultMethodIds tycons = [ mkExportedVanillaId dm_name (mk_dm_ty cls sel_id dm_spec) | tc <- tycons , Just cls <- [tyConClass_maybe tc] , (sel_id, Just (dm_name, dm_spec)) <- classOpItems cls ] where mk_dm_ty :: Class -> Id -> DefMethSpec Type -> Type mk_dm_ty _ sel_id VanillaDM = idType sel_id mk_dm_ty cls _ (GenericDM dm_ty) = mkSpecSigmaTy cls_tvs [pred] dm_ty where cls_tvs = classTyVars cls pred = mkClassPred cls (mkTyVarTys cls_tvs) {- ************************************************************************ * * Building record selectors * * ************************************************************************ -} {- Note [Default method Ids and Template Haskell] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider this (Trac #4169): class Numeric a where fromIntegerNum :: a fromIntegerNum = ... ast :: Q [Dec] ast = [d| instance Numeric Int |] When we typecheck 'ast' we have done the first pass over the class decl (in tcTyClDecls), but we have not yet typechecked the default-method declarations (because they can mention value declarations). So we must bring the default method Ids into scope first (so they can be seen when typechecking the [d| .. |] quote, and typecheck them later. -} {- ************************************************************************ * * Building record selectors * * ************************************************************************ -} mkRecSelBinds :: [TyCon] -> HsValBinds Name -- NB We produce *un-typechecked* bindings, rather like 'deriving' -- This makes life easier, because the later type checking will add -- all necessary type abstractions and applications mkRecSelBinds tycons = ValBindsOut binds sigs where (sigs, binds) = unzip rec_sels rec_sels = map mkRecSelBind [ (tc,fld) | tc <- tycons , fld <- tyConFieldLabels tc ] mkRecSelBind :: (TyCon, FieldLabel) -> (LSig Name, (RecFlag, LHsBinds Name)) mkRecSelBind (tycon, fl) = mkOneRecordSelector all_cons (RecSelData tycon) fl where all_cons = map RealDataCon (tyConDataCons tycon) mkOneRecordSelector :: [ConLike] -> RecSelParent -> FieldLabel -> (LSig Name, (RecFlag, LHsBinds Name)) mkOneRecordSelector all_cons idDetails fl = (L loc (IdSig sel_id), (NonRecursive, unitBag (L loc sel_bind))) where loc = getSrcSpan sel_name lbl = flLabel fl sel_name = flSelector fl sel_id = mkExportedLocalId rec_details sel_name sel_ty rec_details = RecSelId { sel_tycon = idDetails, sel_naughty = is_naughty } -- Find a representative constructor, con1 cons_w_field = conLikesWithFields all_cons [lbl] con1 = ASSERT( not (null cons_w_field) ) head cons_w_field -- Selector type; Note [Polymorphic selectors] field_ty = conLikeFieldType con1 lbl data_tvs = tyCoVarsOfTypeWellScoped data_ty data_tv_set= mkVarSet data_tvs is_naughty = not (tyCoVarsOfType field_ty `subVarSet` data_tv_set) (field_tvs, field_theta, field_tau) = tcSplitSigmaTy field_ty sel_ty | is_naughty = unitTy -- See Note [Naughty record selectors] | otherwise = mkSpecForAllTys data_tvs $ mkPhiTy (conLikeStupidTheta con1) $ -- Urgh! mkFunTy data_ty $ mkSpecForAllTys field_tvs $ mkPhiTy field_theta $ -- req_theta is empty for normal DataCon mkPhiTy req_theta $ field_tau -- Make the binding: sel (C2 { fld = x }) = x -- sel (C7 { fld = x }) = x -- where cons_w_field = [C2,C7] sel_bind = mkTopFunBind Generated sel_lname alts where alts | is_naughty = [mkSimpleMatch [] unit_rhs] | otherwise = map mk_match cons_w_field ++ deflt mk_match con = mkSimpleMatch [L loc (mk_sel_pat con)] (L loc (HsVar (L loc field_var))) mk_sel_pat con = ConPatIn (L loc (getName con)) (RecCon rec_fields) rec_fields = HsRecFields { rec_flds = [rec_field], rec_dotdot = Nothing } rec_field = noLoc (HsRecField { hsRecFieldLbl = L loc (FieldOcc (L loc $ mkVarUnqual lbl) sel_name) , hsRecFieldArg = L loc (VarPat (L loc field_var)) , hsRecPun = False }) sel_lname = L loc sel_name field_var = mkInternalName (mkBuiltinUnique 1) (getOccName sel_name) loc -- Add catch-all default case unless the case is exhaustive -- We do this explicitly so that we get a nice error message that -- mentions this particular record selector deflt | all dealt_with all_cons = [] | otherwise = [mkSimpleMatch [L loc (WildPat placeHolderType)] (mkHsApp (L loc (HsVar (L loc (getName rEC_SEL_ERROR_ID)))) (L loc (HsLit msg_lit)))] -- Do not add a default case unless there are unmatched -- constructors. We must take account of GADTs, else we -- get overlap warning messages from the pattern-match checker -- NB: we need to pass type args for the *representation* TyCon -- to dataConCannotMatch, hence the calculation of inst_tys -- This matters in data families -- data instance T Int a where -- A :: { fld :: Int } -> T Int Bool -- B :: { fld :: Int } -> T Int Char dealt_with :: ConLike -> Bool dealt_with (PatSynCon _) = False -- We can't predict overlap dealt_with con@(RealDataCon dc) = con `elem` cons_w_field || dataConCannotMatch inst_tys dc (univ_tvs, _, eq_spec, _, req_theta, _, data_ty) = conLikeFullSig con1 eq_subst = mkTvSubstPrs (map eqSpecPair eq_spec) inst_tys = substTyVars eq_subst univ_tvs unit_rhs = mkLHsTupleExpr [] msg_lit = HsStringPrim "" (fastStringToByteString lbl) {- Note [Polymorphic selectors] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We take care to build the type of a polymorphic selector in the right order, so that visible type application works. data Ord a => T a = MkT { field :: forall b. (Num a, Show b) => (a, b) } We want field :: forall a. Ord a => T a -> forall b. (Num a, Show b) => (a, b) Note [Naughty record selectors] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A "naughty" field is one for which we can't define a record selector, because an existential type variable would escape. For example: data T = forall a. MkT { x,y::a } We obviously can't define x (MkT v _) = v Nevertheless we *do* put a RecSelId into the type environment so that if the user tries to use 'x' as a selector we can bleat helpfully, rather than saying unhelpfully that 'x' is not in scope. Hence the sel_naughty flag, to identify record selectors that don't really exist. In general, a field is "naughty" if its type mentions a type variable that isn't in the result type of the constructor. Note that this *allows* GADT record selectors (Note [GADT record selectors]) whose types may look like sel :: T [a] -> a For naughty selectors we make a dummy binding sel = () so that the later type-check will add them to the environment, and they'll be exported. The function is never called, because the typechecker spots the sel_naughty field. Note [GADT record selectors] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For GADTs, we require that all constructors with a common field 'f' have the same result type (modulo alpha conversion). [Checked in TcTyClsDecls.checkValidTyCon] E.g. data T where T1 { f :: Maybe a } :: T [a] T2 { f :: Maybe a, y :: b } :: T [a] T3 :: T Int and now the selector takes that result type as its argument: f :: forall a. T [a] -> Maybe a Details: the "real" types of T1,T2 are: T1 :: forall r a. (r~[a]) => a -> T r T2 :: forall r a b. (r~[a]) => a -> b -> T r So the selector loooks like this: f :: forall a. T [a] -> Maybe a f (a:*) (t:T [a]) = case t of T1 c (g:[a]~[c]) (v:Maybe c) -> v `cast` Maybe (right (sym g)) T2 c d (g:[a]~[c]) (v:Maybe c) (w:d) -> v `cast` Maybe (right (sym g)) T3 -> error "T3 does not have field f" Note the forall'd tyvars of the selector are just the free tyvars of the result type; there may be other tyvars in the constructor's type (e.g. 'b' in T2). Note the need for casts in the result! Note [Selector running example] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It's OK to combine GADTs and type families. Here's a running example: data instance T [a] where T1 { fld :: b } :: T [Maybe b] The representation type looks like this data :R7T a where T1 { fld :: b } :: :R7T (Maybe b) and there's coercion from the family type to the representation type :CoR7T a :: T [a] ~ :R7T a The selector we want for fld looks like this: fld :: forall b. T [Maybe b] -> b fld = /\b. \(d::T [Maybe b]). case d `cast` :CoR7T (Maybe b) of T1 (x::b) -> x The scrutinee of the case has type :R7T (Maybe b), which can be gotten by appying the eq_spec to the univ_tvs of the data con. -}
mcschroeder/ghc
compiler/typecheck/TcTyDecls.hs
bsd-3-clause
45,148
3
19
12,828
6,105
3,201
2,904
422
10
{-# LANGUAGE Haskell2010, OverloadedStrings #-} {-# LINE 1 "Network/Wai/Middleware/Jsonp.hs" #-} {-# LANGUAGE RankNTypes, CPP #-} --------------------------------------------------------- -- | -- Module : Network.Wai.Middleware.Jsonp -- Copyright : Michael Snoyman -- License : BSD3 -- -- Maintainer : Michael Snoyman <[email protected]> -- Stability : Unstable -- Portability : portable -- -- Automatic wrapping of JSON responses to convert into JSONP. -- --------------------------------------------------------- module Network.Wai.Middleware.Jsonp (jsonp) where import Network.Wai import Network.Wai.Internal import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as B8 import Blaze.ByteString.Builder (copyByteString) import Blaze.ByteString.Builder.Char8 (fromChar) import Control.Monad (join) import Data.Maybe (fromMaybe) import qualified Data.ByteString as S import Network.HTTP.Types (hAccept, hContentType) -- | Wrap json responses in a jsonp callback. -- -- Basically, if the user requested a \"text\/javascript\" and supplied a -- \"callback\" GET parameter, ask the application for an -- \"application/json\" response, then convert that into a JSONP response, -- having a content type of \"text\/javascript\" and calling the specified -- callback function. jsonp :: Middleware jsonp app env sendResponse = do let accept = fromMaybe B8.empty $ lookup hAccept $ requestHeaders env let callback :: Maybe B8.ByteString callback = if B8.pack "text/javascript" `B8.isInfixOf` accept then join $ lookup "callback" $ queryString env else Nothing let env' = case callback of Nothing -> env Just _ -> env { requestHeaders = changeVal hAccept "application/json" $ requestHeaders env } app env' $ \res -> case callback of Nothing -> sendResponse res Just c -> go c res where go c r@(ResponseBuilder s hs b) = sendResponse $ case checkJSON hs of Nothing -> r Just hs' -> responseBuilder s hs' $ copyByteString c `mappend` fromChar '(' `mappend` b `mappend` fromChar ')' go c r = case checkJSON hs of Just hs' -> addCallback c s hs' wb Nothing -> sendResponse r where (s, hs, wb) = responseToStream r checkJSON hs = case lookup hContentType hs of Just x | B8.pack "application/json" `S.isPrefixOf` x -> Just $ fixHeaders hs _ -> Nothing fixHeaders = changeVal hContentType "text/javascript" addCallback cb s hs wb = wb $ \body -> sendResponse $ responseStream s hs $ \sendChunk flush -> do sendChunk $ copyByteString cb `mappend` fromChar '(' _ <- body sendChunk flush sendChunk $ fromChar ')' changeVal :: Eq a => a -> ByteString -> [(a, ByteString)] -> [(a, ByteString)] changeVal key val old = (key, val) : filter (\(k, _) -> k /= key) old
phischu/fragnix
tests/packages/scotty/Network.Wai.Middleware.Jsonp.hs
bsd-3-clause
3,450
0
16
1,174
710
380
330
65
8
-- | -- Module : $Header$ -- Copyright : (c) 2013-2014 Galois, Inc. -- License : BSD3 -- Maintainer : [email protected] -- Stability : provisional -- Portability : portable {-# LANGUAGE CPP #-} #define DEBUG #ifdef DEBUG {-# LANGUAGE Trustworthy #-} #else {-# LANGUAGE Safe #-} #endif module Cryptol.Utils.Debug where import Cryptol.Utils.PP #ifdef DEBUG import qualified Debug.Trace as X trace :: String -> b -> b trace = X.trace #else trace :: String -> b -> b trace _ x = x #endif ppTrace :: Doc -> b -> b ppTrace d = trace (show d)
TomMD/cryptol
src/Cryptol/Utils/Debug.hs
bsd-3-clause
564
0
7
123
87
57
30
9
1
module UI.Command.App ( App, appArgs, appConfig, AppContext(..) ) where import Data.Default import Control.Monad.Reader import System.Console.GetOpt import Control.Monad (when) import System.Environment (getArgs) import System.Exit ------------------------------------------------------------ -- App -- data (Default config) => AppContext config = AppContext { appContextConfig :: config, appContextArgs :: [String] } type App config = ReaderT (AppContext config) IO -- | Get the application arguments appArgs :: (Default config) => App config [String] appArgs = asks appContextArgs -- | Get the application config appConfig :: (Default config) => App config config appConfig = asks appContextConfig
kfish/ui-command
UI/Command/App.hs
bsd-3-clause
758
0
9
145
181
109
72
19
1
{-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Test.GHC.Gen where #ifdef DEBUG import Test.QuickCheck import SrcLoc import FastString instance Arbitrary SrcSpan where arbitrary = sized $ \s -> do let file = mkFastString "<testing>" l_from <- choose (1, s+1) c_from <- choose (0, s) l_len <- choose (0, s) c_len <- choose (1, s+1) return $ mkSrcSpan (mkSrcLoc file l_from c_from) (mkSrcLoc file (l_from+l_len) (c_from+c_len)) -- XXX: if l_len > 0 then c_len + c_from >= 0 is enough {- instance Show SrcSpan where show s | not (isGoodSrcSpan s) = "<unhelpful span>" | isOneLineSpan s = show (srcSpanStartLine s) ++ ":" ++ let c1 = srcSpanStartCol s c2 = srcSpanEndCol s - 1 in if c1 < c2 then show c1 ++ "-" ++ show c2 else show c1 | otherwise = show (srcSpanStartLine s) ++ ":" ++ show (srcSpanStartCol s) ++ "-" ++ show (srcSpanEndLine s) ++ ":" ++ show (srcSpanEndCol s) -} #endif
CristhianMotoche/scion
lib/Test/GHC/Gen.hs
bsd-3-clause
1,149
0
15
405
176
94
82
3
0
{-| Implementation of the Ganeti confd utilities. This holds a few utility functions that could be useful in both clients and servers. -} {- Copyright (C) 2011, 2012 Google Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -} module Ganeti.Confd.Utils ( getClusterHmac , parseSignedMessage , parseRequest , parseReply , signMessage , getCurrentTime , extractJSONPath ) where import qualified Data.Attoparsec.Text as P import Control.Applicative ((*>)) import qualified Data.ByteString as B import Data.Text (pack) import qualified Text.JSON as J import Ganeti.BasicTypes import Ganeti.Confd.Types import Ganeti.Hash import qualified Ganeti.Constants as C import qualified Ganeti.Path as Path import Ganeti.JSON import Ganeti.Utils -- | Type-adjusted max clock skew constant. maxClockSkew :: Integer maxClockSkew = fromIntegral C.confdMaxClockSkew -- | Returns the HMAC key. getClusterHmac :: IO HashKey getClusterHmac = Path.confdHmacKey >>= fmap B.unpack . B.readFile -- | Parses a signed message. parseSignedMessage :: (J.JSON a) => HashKey -> String -> Result (String, String, a) parseSignedMessage key str = do (SignedMessage hmac msg salt) <- fromJResult "parsing signed message" $ J.decode str parsedMsg <- if verifyMac key (Just salt) msg hmac then fromJResult "parsing message" $ J.decode msg else Bad "HMAC verification failed" return (salt, msg, parsedMsg) -- | Message parsing. This can either result in a good, valid request -- message, or fail in the Result monad. parseRequest :: HashKey -> String -> Integer -> Result (String, ConfdRequest) parseRequest hmac msg curtime = do (salt, origmsg, request) <- parseSignedMessage hmac msg ts <- tryRead "Parsing timestamp" salt::Result Integer if abs (ts - curtime) > maxClockSkew then fail "Too old/too new timestamp or clock skew" else return (origmsg, request) -- | Message parsing. This can either result in a good, valid reply -- message, or fail in the Result monad. -- It also checks that the salt in the message corresponds to the one -- that is expected parseReply :: HashKey -> String -> String -> Result (String, ConfdReply) parseReply hmac msg expSalt = do (salt, origmsg, reply) <- parseSignedMessage hmac msg if salt /= expSalt then fail "The received salt differs from the expected salt" else return (origmsg, reply) -- | Signs a message with a given key and salt. signMessage :: HashKey -> String -> String -> SignedMessage signMessage key salt msg = SignedMessage { signedMsgMsg = msg , signedMsgSalt = salt , signedMsgHmac = hmac } where hmac = computeMac key (Just salt) msg data Pointer = Pointer [String] deriving (Show, Eq) -- | Parse a fixed size Int. readInteger :: String -> J.Result Int readInteger = either J.Error J.Ok . P.parseOnly P.decimal . pack -- | Parse a path for a JSON structure. pointerFromString :: String -> J.Result Pointer pointerFromString s = either J.Error J.Ok . P.parseOnly parser $ pack s where parser = do _ <- P.char '/' tokens <- token `P.sepBy1` P.char '/' return $ Pointer tokens token = P.choice [P.many1 (P.choice [ escaped , P.satisfy $ P.notInClass "~/"]) , P.endOfInput *> return ""] escaped = P.choice [escapedSlash, escapedTilde] escapedSlash = P.string (pack "~1") *> return '/' escapedTilde = P.string (pack "~0") *> return '~' -- | Use a Pointer to access any value nested in a JSON object. extractValue :: J.JSON a => Pointer -> a -> J.Result J.JSValue extractValue (Pointer l) json = getJSValue l $ J.showJSON json where indexWithString x (J.JSObject object) = J.valFromObj x object indexWithString x (J.JSArray list) = do i <- readInteger x if 0 <= i && i < length list then return $ list !! i else J.Error ("list index " ++ show i ++ " out of bounds") indexWithString _ _ = J.Error "Atomic value was indexed" getJSValue :: [String] -> J.JSValue -> J.Result J.JSValue getJSValue [] js = J.Ok js getJSValue (x:xs) js = do value <- indexWithString x js getJSValue xs value -- | Extract a 'JSValue' from an object at the position defined by the path. -- -- The path syntax follows RCF6901. Error is returned if the path doesn't -- exist, Ok if the path leads to an valid value. -- -- JSON pointer syntax according to RFC6901: -- -- > "/path/0/x" => Pointer ["path", "0", "x"] -- -- This accesses 1 in the following JSON: -- -- > { "path": { "0": { "x": 1 } } } -- -- or the following: -- -- > { "path": [{"x": 1}] } extractJSONPath :: J.JSON a => String -> a -> J.Result J.JSValue extractJSONPath path obj = do pointer <- pointerFromString path extractValue pointer obj
grnet/snf-ganeti
src/Ganeti/Confd/Utils.hs
bsd-2-clause
6,048
0
15
1,265
1,194
631
563
90
5
{-# language QuasiQuotes #-} module Planetary.Library.Management (resolvedDecls) where import NeatInterpolation import Planetary.Core -- import Planetary.Support.NameResolution import Planetary.Support.Parser decls = forceDeclarations [text| data LanguageDiff = | <Apply {<Syntax> -> <Syntax>} {<Semantics> -> <Semantics>}> |] resolvedDecls :: ResolvedDecls resolvedDecls = mempty -- Right resolvedDecls = resolveDecls (todo "predefined") decls
joelburget/interplanetary-computation
src/Planetary/Library/Management.hs
bsd-3-clause
451
0
5
53
51
34
17
8
1
{- (c) The University of Glasgow 2006 (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 -} {-# LANGUAGE RankNTypes, TypeFamilies #-} module ETA.Core.TrieMap( CoreMap, emptyCoreMap, extendCoreMap, lookupCoreMap, foldCoreMap, TypeMap, emptyTypeMap, extendTypeMap, lookupTypeMap, foldTypeMap, CoercionMap, MaybeMap, ListMap, TrieMap(..), insertTM, deleteTM, lookupTypeMapTyCon ) where import ETA.Core.CoreSyn import ETA.Types.Coercion import ETA.BasicTypes.Literal import ETA.BasicTypes.Name import ETA.Types.Type import ETA.Types.TypeRep import ETA.Types.TyCon(TyCon) import ETA.BasicTypes.Var import ETA.Utils.UniqFM import ETA.BasicTypes.Unique( Unique ) import ETA.Utils.FastString(FastString) import ETA.Types.CoAxiom(CoAxiomRule(coaxrName)) import qualified Data.Map as Map import qualified Data.IntMap as IntMap import ETA.BasicTypes.VarEnv import ETA.BasicTypes.NameEnv import ETA.Utils.Outputable import Control.Monad( (>=>) ) {- This module implements TrieMaps, which are finite mappings whose key is a structured value like a CoreExpr or Type. The code is very regular and boilerplate-like, but there is some neat handling of *binders*. In effect they are deBruijn numbered on the fly. ************************************************************************ * * The TrieMap class * * ************************************************************************ -} type XT a = Maybe a -> Maybe a -- How to alter a non-existent elt (Nothing) -- or an existing elt (Just) class TrieMap m where type Key m :: * emptyTM :: m a lookupTM :: forall b. Key m -> m b -> Maybe b alterTM :: forall b. Key m -> XT b -> m b -> m b mapTM :: (a->b) -> m a -> m b foldTM :: (a -> b -> b) -> m a -> b -> b -- The unusual argument order here makes -- it easy to compose calls to foldTM; -- see for example fdE below insertTM :: TrieMap m => Key m -> a -> m a -> m a insertTM k v m = alterTM k (\_ -> Just v) m deleteTM :: TrieMap m => Key m -> m a -> m a deleteTM k m = alterTM k (\_ -> Nothing) m ---------------------- -- Recall that -- Control.Monad.(>=>) :: (a -> Maybe b) -> (b -> Maybe c) -> a -> Maybe c (>.>) :: (a -> b) -> (b -> c) -> a -> c -- Reverse function composition (do f first, then g) infixr 1 >.> (f >.> g) x = g (f x) infixr 1 |>, |>> (|>) :: a -> (a->b) -> b -- Reverse application x |> f = f x ---------------------- (|>>) :: TrieMap m2 => (XT (m2 a) -> m1 (m2 a) -> m1 (m2 a)) -> (m2 a -> m2 a) -> m1 (m2 a) -> m1 (m2 a) (|>>) f g = f (Just . g . deMaybe) deMaybe :: TrieMap m => Maybe (m a) -> m a deMaybe Nothing = emptyTM deMaybe (Just m) = m {- ************************************************************************ * * IntMaps * * ************************************************************************ -} instance TrieMap IntMap.IntMap where type Key IntMap.IntMap = Int emptyTM = IntMap.empty lookupTM k m = IntMap.lookup k m alterTM = xtInt foldTM k m z = IntMap.fold k z m mapTM f m = IntMap.map f m xtInt :: Int -> XT a -> IntMap.IntMap a -> IntMap.IntMap a xtInt k f m = IntMap.alter f k m instance Ord k => TrieMap (Map.Map k) where type Key (Map.Map k) = k emptyTM = Map.empty lookupTM = Map.lookup alterTM k f m = Map.alter f k m foldTM k m z = Map.fold k z m mapTM f m = Map.map f m instance TrieMap UniqFM where type Key UniqFM = Unique emptyTM = emptyUFM lookupTM k m = lookupUFM m k alterTM k f m = alterUFM f m k foldTM k m z = foldUFM k z m mapTM f m = mapUFM f m {- ************************************************************************ * * Lists * * ************************************************************************ If m is a map from k -> val then (MaybeMap m) is a map from (Maybe k) -> val -} data MaybeMap m a = MM { mm_nothing :: Maybe a, mm_just :: m a } instance TrieMap m => TrieMap (MaybeMap m) where type Key (MaybeMap m) = Maybe (Key m) emptyTM = MM { mm_nothing = Nothing, mm_just = emptyTM } lookupTM = lkMaybe lookupTM alterTM = xtMaybe alterTM foldTM = fdMaybe mapTM = mapMb mapMb :: TrieMap m => (a->b) -> MaybeMap m a -> MaybeMap m b mapMb f (MM { mm_nothing = mn, mm_just = mj }) = MM { mm_nothing = fmap f mn, mm_just = mapTM f mj } lkMaybe :: TrieMap m => (forall b. k -> m b -> Maybe b) -> Maybe k -> MaybeMap m a -> Maybe a lkMaybe _ Nothing = mm_nothing lkMaybe lk (Just x) = mm_just >.> lk x xtMaybe :: TrieMap m => (forall b. k -> XT b -> m b -> m b) -> Maybe k -> XT a -> MaybeMap m a -> MaybeMap m a xtMaybe _ Nothing f m = m { mm_nothing = f (mm_nothing m) } xtMaybe tr (Just x) f m = m { mm_just = mm_just m |> tr x f } fdMaybe :: TrieMap m => (a -> b -> b) -> MaybeMap m a -> b -> b fdMaybe k m = foldMaybe k (mm_nothing m) . foldTM k (mm_just m) -------------------- data ListMap m a = LM { lm_nil :: Maybe a , lm_cons :: m (ListMap m a) } instance TrieMap m => TrieMap (ListMap m) where type Key (ListMap m) = [Key m] emptyTM = LM { lm_nil = Nothing, lm_cons = emptyTM } lookupTM = lkList lookupTM alterTM = xtList alterTM foldTM = fdList mapTM = mapList mapList :: TrieMap m => (a->b) -> ListMap m a -> ListMap m b mapList f (LM { lm_nil = mnil, lm_cons = mcons }) = LM { lm_nil = fmap f mnil, lm_cons = mapTM (mapTM f) mcons } lkList :: TrieMap m => (forall b. k -> m b -> Maybe b) -> [k] -> ListMap m a -> Maybe a lkList _ [] = lm_nil lkList lk (x:xs) = lm_cons >.> lk x >=> lkList lk xs xtList :: TrieMap m => (forall b. k -> XT b -> m b -> m b) -> [k] -> XT a -> ListMap m a -> ListMap m a xtList _ [] f m = m { lm_nil = f (lm_nil m) } xtList tr (x:xs) f m = m { lm_cons = lm_cons m |> tr x |>> xtList tr xs f } fdList :: forall m a b. TrieMap m => (a -> b -> b) -> ListMap m a -> b -> b fdList k m = foldMaybe k (lm_nil m) . foldTM (fdList k) (lm_cons m) foldMaybe :: (a -> b -> b) -> Maybe a -> b -> b foldMaybe _ Nothing b = b foldMaybe k (Just a) b = k a b {- ************************************************************************ * * Basic maps * * ************************************************************************ -} lkNamed :: NamedThing n => n -> NameEnv a -> Maybe a lkNamed n env = lookupNameEnv env (getName n) xtNamed :: NamedThing n => n -> XT a -> NameEnv a -> NameEnv a xtNamed tc f m = alterNameEnv f m (getName tc) ------------------------ type LiteralMap a = Map.Map Literal a emptyLiteralMap :: LiteralMap a emptyLiteralMap = emptyTM lkLit :: Literal -> LiteralMap a -> Maybe a lkLit = lookupTM xtLit :: Literal -> XT a -> LiteralMap a -> LiteralMap a xtLit = alterTM {- ************************************************************************ * * CoreMap * * ************************************************************************ Note [Binders] ~~~~~~~~~~~~~~ * In general we check binders as late as possible because types are less likely to differ than expression structure. That's why cm_lam :: CoreMap (TypeMap a) rather than cm_lam :: TypeMap (CoreMap a) * We don't need to look at the type of some binders, notalby - the case binder in (Case _ b _ _) - the binders in an alternative because they are totally fixed by the context Note [Empty case alternatives] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * For a key (Case e b ty (alt:alts)) we don't need to look the return type 'ty', because every alternative has that type. * For a key (Case e b ty []) we MUST look at the return type 'ty', because otherwise (Case (error () "urk") _ Int []) would compare equal to (Case (error () "urk") _ Bool []) which is utterly wrong (Trac #6097) We could compare the return type regardless, but the wildly common case is that it's unnecesary, so we have two fields (cm_case and cm_ecase) for the two possibilities. Only cm_ecase looks at the type. See also Note [Empty case alternatives] in CoreSyn. -} data CoreMap a = EmptyCM | CM { cm_var :: VarMap a , cm_lit :: LiteralMap a , cm_co :: CoercionMap a , cm_type :: TypeMap a , cm_cast :: CoreMap (CoercionMap a) , cm_tick :: CoreMap (TickishMap a) , cm_app :: CoreMap (CoreMap a) , cm_lam :: CoreMap (TypeMap a) -- Note [Binders] , cm_letn :: CoreMap (CoreMap (BndrMap a)) , cm_letr :: ListMap CoreMap (CoreMap (ListMap BndrMap a)) , cm_case :: CoreMap (ListMap AltMap a) , cm_ecase :: CoreMap (TypeMap a) -- Note [Empty case alternatives] } wrapEmptyCM :: CoreMap a wrapEmptyCM = CM { cm_var = emptyTM, cm_lit = emptyLiteralMap , cm_co = emptyTM, cm_type = emptyTM , cm_cast = emptyTM, cm_app = emptyTM , cm_lam = emptyTM, cm_letn = emptyTM , cm_letr = emptyTM, cm_case = emptyTM , cm_ecase = emptyTM, cm_tick = emptyTM } instance TrieMap CoreMap where type Key CoreMap = CoreExpr emptyTM = EmptyCM lookupTM = lkE emptyCME alterTM = xtE emptyCME foldTM = fdE mapTM = mapE -------------------------- mapE :: (a->b) -> CoreMap a -> CoreMap b mapE _ EmptyCM = EmptyCM mapE f (CM { cm_var = cvar, cm_lit = clit , cm_co = cco, cm_type = ctype , cm_cast = ccast , cm_app = capp , cm_lam = clam, cm_letn = cletn , cm_letr = cletr, cm_case = ccase , cm_ecase = cecase, cm_tick = ctick }) = CM { cm_var = mapTM f cvar, cm_lit = mapTM f clit , cm_co = mapTM f cco, cm_type = mapTM f ctype , cm_cast = mapTM (mapTM f) ccast, cm_app = mapTM (mapTM f) capp , cm_lam = mapTM (mapTM f) clam, cm_letn = mapTM (mapTM (mapTM f)) cletn , cm_letr = mapTM (mapTM (mapTM f)) cletr, cm_case = mapTM (mapTM f) ccase , cm_ecase = mapTM (mapTM f) cecase, cm_tick = mapTM (mapTM f) ctick } -------------------------- lookupCoreMap :: CoreMap a -> CoreExpr -> Maybe a lookupCoreMap cm e = lkE emptyCME e cm extendCoreMap :: CoreMap a -> CoreExpr -> a -> CoreMap a extendCoreMap m e v = xtE emptyCME e (\_ -> Just v) m foldCoreMap :: (a -> b -> b) -> b -> CoreMap a -> b foldCoreMap k z m = fdE k m z emptyCoreMap :: CoreMap a emptyCoreMap = EmptyCM instance Outputable a => Outputable (CoreMap a) where ppr m = text "CoreMap elts" <+> ppr (foldCoreMap (:) [] m) ------------------------- fdE :: (a -> b -> b) -> CoreMap a -> b -> b fdE _ EmptyCM = \z -> z fdE k m = foldTM k (cm_var m) . foldTM k (cm_lit m) . foldTM k (cm_co m) . foldTM k (cm_type m) . foldTM (foldTM k) (cm_cast m) . foldTM (foldTM k) (cm_tick m) . foldTM (foldTM k) (cm_app m) . foldTM (foldTM k) (cm_lam m) . foldTM (foldTM (foldTM k)) (cm_letn m) . foldTM (foldTM (foldTM k)) (cm_letr m) . foldTM (foldTM k) (cm_case m) . foldTM (foldTM k) (cm_ecase m) lkE :: CmEnv -> CoreExpr -> CoreMap a -> Maybe a -- lkE: lookup in trie for expressions lkE env expr cm | EmptyCM <- cm = Nothing | otherwise = go expr cm where go (Var v) = cm_var >.> lkVar env v go (Lit l) = cm_lit >.> lkLit l go (Type t) = cm_type >.> lkT env t go (Coercion c) = cm_co >.> lkC env c go (Cast e c) = cm_cast >.> lkE env e >=> lkC env c go (Tick tickish e) = cm_tick >.> lkE env e >=> lkTickish tickish go (App e1 e2) = cm_app >.> lkE env e2 >=> lkE env e1 go (Lam v e) = cm_lam >.> lkE (extendCME env v) e >=> lkBndr env v go (Let (NonRec b r) e) = cm_letn >.> lkE env r >=> lkE (extendCME env b) e >=> lkBndr env b go (Let (Rec prs) e) = let (bndrs,rhss) = unzip prs env1 = extendCMEs env bndrs in cm_letr >.> lkList (lkE env1) rhss >=> lkE env1 e >=> lkList (lkBndr env1) bndrs go (Case e b ty as) -- See Note [Empty case alternatives] | null as = cm_ecase >.> lkE env e >=> lkT env ty | otherwise = cm_case >.> lkE env e >=> lkList (lkA (extendCME env b)) as xtE :: CmEnv -> CoreExpr -> XT a -> CoreMap a -> CoreMap a xtE env e f EmptyCM = xtE env e f wrapEmptyCM xtE env (Var v) f m = m { cm_var = cm_var m |> xtVar env v f } xtE env (Type t) f m = m { cm_type = cm_type m |> xtT env t f } xtE env (Coercion c) f m = m { cm_co = cm_co m |> xtC env c f } xtE _ (Lit l) f m = m { cm_lit = cm_lit m |> xtLit l f } xtE env (Cast e c) f m = m { cm_cast = cm_cast m |> xtE env e |>> xtC env c f } xtE env (Tick t e) f m = m { cm_tick = cm_tick m |> xtE env e |>> xtTickish t f } xtE env (App e1 e2) f m = m { cm_app = cm_app m |> xtE env e2 |>> xtE env e1 f } xtE env (Lam v e) f m = m { cm_lam = cm_lam m |> xtE (extendCME env v) e |>> xtBndr env v f } xtE env (Let (NonRec b r) e) f m = m { cm_letn = cm_letn m |> xtE (extendCME env b) e |>> xtE env r |>> xtBndr env b f } xtE env (Let (Rec prs) e) f m = m { cm_letr = let (bndrs,rhss) = unzip prs env1 = extendCMEs env bndrs in cm_letr m |> xtList (xtE env1) rhss |>> xtE env1 e |>> xtList (xtBndr env1) bndrs f } xtE env (Case e b ty as) f m | null as = m { cm_ecase = cm_ecase m |> xtE env e |>> xtT env ty f } | otherwise = m { cm_case = cm_case m |> xtE env e |>> let env1 = extendCME env b in xtList (xtA env1) as f } type TickishMap a = Map.Map (Tickish Id) a lkTickish :: Tickish Id -> TickishMap a -> Maybe a lkTickish = lookupTM xtTickish :: Tickish Id -> XT a -> TickishMap a -> TickishMap a xtTickish = alterTM ------------------------ data AltMap a -- A single alternative = AM { am_deflt :: CoreMap a , am_data :: NameEnv (CoreMap a) , am_lit :: LiteralMap (CoreMap a) } instance TrieMap AltMap where type Key AltMap = CoreAlt emptyTM = AM { am_deflt = emptyTM , am_data = emptyNameEnv , am_lit = emptyLiteralMap } lookupTM = lkA emptyCME alterTM = xtA emptyCME foldTM = fdA mapTM = mapA mapA :: (a->b) -> AltMap a -> AltMap b mapA f (AM { am_deflt = adeflt, am_data = adata, am_lit = alit }) = AM { am_deflt = mapTM f adeflt , am_data = mapNameEnv (mapTM f) adata , am_lit = mapTM (mapTM f) alit } lkA :: CmEnv -> CoreAlt -> AltMap a -> Maybe a lkA env (DEFAULT, _, rhs) = am_deflt >.> lkE env rhs lkA env (LitAlt lit, _, rhs) = am_lit >.> lkLit lit >=> lkE env rhs lkA env (DataAlt dc, bs, rhs) = am_data >.> lkNamed dc >=> lkE (extendCMEs env bs) rhs xtA :: CmEnv -> CoreAlt -> XT a -> AltMap a -> AltMap a xtA env (DEFAULT, _, rhs) f m = m { am_deflt = am_deflt m |> xtE env rhs f } xtA env (LitAlt l, _, rhs) f m = m { am_lit = am_lit m |> xtLit l |>> xtE env rhs f } xtA env (DataAlt d, bs, rhs) f m = m { am_data = am_data m |> xtNamed d |>> xtE (extendCMEs env bs) rhs f } fdA :: (a -> b -> b) -> AltMap a -> b -> b fdA k m = foldTM k (am_deflt m) . foldTM (foldTM k) (am_data m) . foldTM (foldTM k) (am_lit m) {- ************************************************************************ * * Coercions * * ************************************************************************ -} data CoercionMap a = EmptyKM | KM { km_refl :: RoleMap (TypeMap a) , km_tc_app :: RoleMap (NameEnv (ListMap CoercionMap a)) , km_app :: CoercionMap (CoercionMap a) , km_forall :: CoercionMap (TypeMap a) , km_var :: VarMap a , km_axiom :: NameEnv (IntMap.IntMap (ListMap CoercionMap a)) , km_univ :: RoleMap (TypeMap (TypeMap a)) , km_sym :: CoercionMap a , km_trans :: CoercionMap (CoercionMap a) , km_nth :: IntMap.IntMap (CoercionMap a) , km_left :: CoercionMap a , km_right :: CoercionMap a , km_inst :: CoercionMap (TypeMap a) , km_sub :: CoercionMap a , km_axiom_rule :: Map.Map FastString (ListMap TypeMap (ListMap CoercionMap a)) } wrapEmptyKM :: CoercionMap a wrapEmptyKM = KM { km_refl = emptyTM, km_tc_app = emptyTM , km_app = emptyTM, km_forall = emptyTM , km_var = emptyTM, km_axiom = emptyNameEnv , km_univ = emptyTM, km_sym = emptyTM, km_trans = emptyTM , km_nth = emptyTM, km_left = emptyTM, km_right = emptyTM , km_inst = emptyTM, km_sub = emptyTM , km_axiom_rule = emptyTM } instance TrieMap CoercionMap where type Key CoercionMap = Coercion emptyTM = EmptyKM lookupTM = lkC emptyCME alterTM = xtC emptyCME foldTM = fdC mapTM = mapC mapC :: (a->b) -> CoercionMap a -> CoercionMap b mapC _ EmptyKM = EmptyKM mapC f (KM { km_refl = krefl, km_tc_app = ktc , km_app = kapp, km_forall = kforall , km_var = kvar, km_axiom = kax , km_univ = kuniv , km_sym = ksym, km_trans = ktrans , km_nth = knth, km_left = kml, km_right = kmr , km_inst = kinst, km_sub = ksub , km_axiom_rule = kaxr }) = KM { km_refl = mapTM (mapTM f) krefl , km_tc_app = mapTM (mapNameEnv (mapTM f)) ktc , km_app = mapTM (mapTM f) kapp , km_forall = mapTM (mapTM f) kforall , km_var = mapTM f kvar , km_axiom = mapNameEnv (IntMap.map (mapTM f)) kax , km_univ = mapTM (mapTM (mapTM f)) kuniv , km_sym = mapTM f ksym , km_trans = mapTM (mapTM f) ktrans , km_nth = IntMap.map (mapTM f) knth , km_left = mapTM f kml , km_right = mapTM f kmr , km_inst = mapTM (mapTM f) kinst , km_sub = mapTM f ksub , km_axiom_rule = mapTM (mapTM (mapTM f)) kaxr } lkC :: CmEnv -> Coercion -> CoercionMap a -> Maybe a lkC env co m | EmptyKM <- m = Nothing | otherwise = go co m where go (Refl r ty) = km_refl >.> lookupTM r >=> lkT env ty go (TyConAppCo r tc cs) = km_tc_app >.> lookupTM r >=> lkNamed tc >=> lkList (lkC env) cs go (AxiomInstCo ax ind cs) = km_axiom >.> lkNamed ax >=> lookupTM ind >=> lkList (lkC env) cs go (AppCo c1 c2) = km_app >.> lkC env c1 >=> lkC env c2 go (TransCo c1 c2) = km_trans >.> lkC env c1 >=> lkC env c2 -- the provenance is not used in the map go (UnivCo _ r t1 t2) = km_univ >.> lookupTM r >=> lkT env t1 >=> lkT env t2 go (InstCo c t) = km_inst >.> lkC env c >=> lkT env t go (ForAllCo v c) = km_forall >.> lkC (extendCME env v) c >=> lkBndr env v go (CoVarCo v) = km_var >.> lkVar env v go (SymCo c) = km_sym >.> lkC env c go (NthCo n c) = km_nth >.> lookupTM n >=> lkC env c go (LRCo CLeft c) = km_left >.> lkC env c go (LRCo CRight c) = km_right >.> lkC env c go (SubCo c) = km_sub >.> lkC env c go (AxiomRuleCo co ts cs) = km_axiom_rule >.> lookupTM (coaxrName co) >=> lkList (lkT env) ts >=> lkList (lkC env) cs xtC :: CmEnv -> Coercion -> XT a -> CoercionMap a -> CoercionMap a xtC env co f EmptyKM = xtC env co f wrapEmptyKM xtC env (Refl r ty) f m = m { km_refl = km_refl m |> xtR r |>> xtT env ty f } xtC env (TyConAppCo r tc cs) f m = m { km_tc_app = km_tc_app m |> xtR r |>> xtNamed tc |>> xtList (xtC env) cs f } xtC env (AxiomInstCo ax ind cs) f m = m { km_axiom = km_axiom m |> xtNamed ax |>> xtInt ind |>> xtList (xtC env) cs f } xtC env (AppCo c1 c2) f m = m { km_app = km_app m |> xtC env c1 |>> xtC env c2 f } xtC env (TransCo c1 c2) f m = m { km_trans = km_trans m |> xtC env c1 |>> xtC env c2 f } -- the provenance is not used in the map xtC env (UnivCo _ r t1 t2) f m = m { km_univ = km_univ m |> xtR r |>> xtT env t1 |>> xtT env t2 f } xtC env (InstCo c t) f m = m { km_inst = km_inst m |> xtC env c |>> xtT env t f } xtC env (ForAllCo v c) f m = m { km_forall = km_forall m |> xtC (extendCME env v) c |>> xtBndr env v f } xtC env (CoVarCo v) f m = m { km_var = km_var m |> xtVar env v f } xtC env (SymCo c) f m = m { km_sym = km_sym m |> xtC env c f } xtC env (NthCo n c) f m = m { km_nth = km_nth m |> xtInt n |>> xtC env c f } xtC env (LRCo CLeft c) f m = m { km_left = km_left m |> xtC env c f } xtC env (LRCo CRight c) f m = m { km_right = km_right m |> xtC env c f } xtC env (SubCo c) f m = m { km_sub = km_sub m |> xtC env c f } xtC env (AxiomRuleCo co ts cs) f m = m { km_axiom_rule = km_axiom_rule m |> alterTM (coaxrName co) |>> xtList (xtT env) ts |>> xtList (xtC env) cs f} fdC :: (a -> b -> b) -> CoercionMap a -> b -> b fdC _ EmptyKM = \z -> z fdC k m = foldTM (foldTM k) (km_refl m) . foldTM (foldTM (foldTM k)) (km_tc_app m) . foldTM (foldTM k) (km_app m) . foldTM (foldTM k) (km_forall m) . foldTM k (km_var m) . foldTM (foldTM (foldTM k)) (km_axiom m) . foldTM (foldTM (foldTM k)) (km_univ m) . foldTM k (km_sym m) . foldTM (foldTM k) (km_trans m) . foldTM (foldTM k) (km_nth m) . foldTM k (km_left m) . foldTM k (km_right m) . foldTM (foldTM k) (km_inst m) . foldTM k (km_sub m) . foldTM (foldTM (foldTM k)) (km_axiom_rule m) newtype RoleMap a = RM { unRM :: (IntMap.IntMap a) } instance TrieMap RoleMap where type Key RoleMap = Role emptyTM = RM emptyTM lookupTM = lkR alterTM = xtR foldTM = fdR mapTM = mapR lkR :: Role -> RoleMap a -> Maybe a lkR Nominal = lookupTM 1 . unRM lkR Representational = lookupTM 2 . unRM lkR Phantom = lookupTM 3 . unRM xtR :: Role -> XT a -> RoleMap a -> RoleMap a xtR Nominal f = RM . alterTM 1 f . unRM xtR Representational f = RM . alterTM 2 f . unRM xtR Phantom f = RM . alterTM 3 f . unRM fdR :: (a -> b -> b) -> RoleMap a -> b -> b fdR f (RM m) = foldTM f m mapR :: (a -> b) -> RoleMap a -> RoleMap b mapR f = RM . mapTM f . unRM {- ************************************************************************ * * Types * * ************************************************************************ -} data TypeMap a = EmptyTM | TM { tm_var :: VarMap a , tm_app :: TypeMap (TypeMap a) , tm_fun :: TypeMap (TypeMap a) , tm_tc_app :: NameEnv (ListMap TypeMap a) , tm_forall :: TypeMap (BndrMap a) , tm_tylit :: TyLitMap a } instance Outputable a => Outputable (TypeMap a) where ppr m = text "TypeMap elts" <+> ppr (foldTypeMap (:) [] m) foldTypeMap :: (a -> b -> b) -> b -> TypeMap a -> b foldTypeMap k z m = fdT k m z emptyTypeMap :: TypeMap a emptyTypeMap = EmptyTM lookupTypeMap :: TypeMap a -> Type -> Maybe a lookupTypeMap cm t = lkT emptyCME t cm -- Returns the type map entries that have keys starting with the given tycon. -- This only considers saturated applications (i.e. TyConApp ones). lookupTypeMapTyCon :: TypeMap a -> TyCon -> [a] lookupTypeMapTyCon EmptyTM _ = [] lookupTypeMapTyCon TM { tm_tc_app = cs } tc = case lookupUFM cs tc of Nothing -> [] Just xs -> foldTM (:) xs [] extendTypeMap :: TypeMap a -> Type -> a -> TypeMap a extendTypeMap m t v = xtT emptyCME t (\_ -> Just v) m wrapEmptyTypeMap :: TypeMap a wrapEmptyTypeMap = TM { tm_var = emptyTM , tm_app = EmptyTM , tm_fun = EmptyTM , tm_tc_app = emptyNameEnv , tm_forall = EmptyTM , tm_tylit = emptyTyLitMap } instance TrieMap TypeMap where type Key TypeMap = Type emptyTM = EmptyTM lookupTM = lkT emptyCME alterTM = xtT emptyCME foldTM = fdT mapTM = mapT mapT :: (a->b) -> TypeMap a -> TypeMap b mapT _ EmptyTM = EmptyTM mapT f (TM { tm_var = tvar, tm_app = tapp, tm_fun = tfun , tm_tc_app = ttcapp, tm_forall = tforall, tm_tylit = tlit }) = TM { tm_var = mapTM f tvar , tm_app = mapTM (mapTM f) tapp , tm_fun = mapTM (mapTM f) tfun , tm_tc_app = mapNameEnv (mapTM f) ttcapp , tm_forall = mapTM (mapTM f) tforall , tm_tylit = mapTM f tlit } ----------------- lkT :: CmEnv -> Type -> TypeMap a -> Maybe a lkT env ty m | EmptyTM <- m = Nothing | otherwise = go ty m where go ty | Just ty' <- coreView ty = go ty' go (TyVarTy v) = tm_var >.> lkVar env v go (AppTy t1 t2) = tm_app >.> lkT env t1 >=> lkT env t2 go (FunTy t1 t2) = tm_fun >.> lkT env t1 >=> lkT env t2 go (TyConApp tc tys) = tm_tc_app >.> lkNamed tc >=> lkList (lkT env) tys go (LitTy l) = tm_tylit >.> lkTyLit l go (ForAllTy tv ty) = tm_forall >.> lkT (extendCME env tv) ty >=> lkBndr env tv ----------------- xtT :: CmEnv -> Type -> XT a -> TypeMap a -> TypeMap a xtT env ty f m | EmptyTM <- m = xtT env ty f wrapEmptyTypeMap | Just ty' <- coreView ty = xtT env ty' f m xtT env (TyVarTy v) f m = m { tm_var = tm_var m |> xtVar env v f } xtT env (AppTy t1 t2) f m = m { tm_app = tm_app m |> xtT env t1 |>> xtT env t2 f } xtT env (FunTy t1 t2) f m = m { tm_fun = tm_fun m |> xtT env t1 |>> xtT env t2 f } xtT env (ForAllTy tv ty) f m = m { tm_forall = tm_forall m |> xtT (extendCME env tv) ty |>> xtBndr env tv f } xtT env (TyConApp tc tys) f m = m { tm_tc_app = tm_tc_app m |> xtNamed tc |>> xtList (xtT env) tys f } xtT _ (LitTy l) f m = m { tm_tylit = tm_tylit m |> xtTyLit l f } fdT :: (a -> b -> b) -> TypeMap a -> b -> b fdT _ EmptyTM = \z -> z fdT k m = foldTM k (tm_var m) . foldTM (foldTM k) (tm_app m) . foldTM (foldTM k) (tm_fun m) . foldTM (foldTM k) (tm_tc_app m) . foldTM (foldTM k) (tm_forall m) . foldTyLit k (tm_tylit m) ------------------------ data TyLitMap a = TLM { tlm_number :: Map.Map Integer a , tlm_string :: Map.Map FastString a } instance TrieMap TyLitMap where type Key TyLitMap = TyLit emptyTM = emptyTyLitMap lookupTM = lkTyLit alterTM = xtTyLit foldTM = foldTyLit mapTM = mapTyLit emptyTyLitMap :: TyLitMap a emptyTyLitMap = TLM { tlm_number = Map.empty, tlm_string = Map.empty } mapTyLit :: (a->b) -> TyLitMap a -> TyLitMap b mapTyLit f (TLM { tlm_number = tn, tlm_string = ts }) = TLM { tlm_number = Map.map f tn, tlm_string = Map.map f ts } lkTyLit :: TyLit -> TyLitMap a -> Maybe a lkTyLit l = case l of NumTyLit n -> tlm_number >.> Map.lookup n StrTyLit n -> tlm_string >.> Map.lookup n xtTyLit :: TyLit -> XT a -> TyLitMap a -> TyLitMap a xtTyLit l f m = case l of NumTyLit n -> m { tlm_number = tlm_number m |> Map.alter f n } StrTyLit n -> m { tlm_string = tlm_string m |> Map.alter f n } foldTyLit :: (a -> b -> b) -> TyLitMap a -> b -> b foldTyLit l m = flip (Map.fold l) (tlm_string m) . flip (Map.fold l) (tlm_number m) {- ************************************************************************ * * Variables * * ************************************************************************ -} type BoundVar = Int -- Bound variables are deBruijn numbered type BoundVarMap a = IntMap.IntMap a data CmEnv = CME { cme_next :: BoundVar , cme_env :: VarEnv BoundVar } emptyCME :: CmEnv emptyCME = CME { cme_next = 0, cme_env = emptyVarEnv } extendCME :: CmEnv -> Var -> CmEnv extendCME (CME { cme_next = bv, cme_env = env }) v = CME { cme_next = bv+1, cme_env = extendVarEnv env v bv } extendCMEs :: CmEnv -> [Var] -> CmEnv extendCMEs env vs = foldl extendCME env vs lookupCME :: CmEnv -> Var -> Maybe BoundVar lookupCME (CME { cme_env = env }) v = lookupVarEnv env v --------- Variable binders ------------- -- | A 'BndrMap' is a 'TypeMap' which allows us to distinguish between -- binding forms whose binders have different types. For example, -- if we are doing a 'TrieMap' lookup on @\(x :: Int) -> ()@, we should -- not pick up an entry in the 'TrieMap' for @\(x :: Bool) -> ()@: -- we can disambiguate this by matching on the type (or kind, if this -- a binder in a type) of the binder. type BndrMap = TypeMap lkBndr :: CmEnv -> Var -> BndrMap a -> Maybe a lkBndr env v m = lkT env (varType v) m xtBndr :: CmEnv -> Var -> XT a -> BndrMap a -> BndrMap a xtBndr env v f = xtT env (varType v) f --------- Variable occurrence ------------- data VarMap a = VM { vm_bvar :: BoundVarMap a -- Bound variable , vm_fvar :: VarEnv a } -- Free variable instance TrieMap VarMap where type Key VarMap = Var emptyTM = VM { vm_bvar = IntMap.empty, vm_fvar = emptyVarEnv } lookupTM = lkVar emptyCME alterTM = xtVar emptyCME foldTM = fdVar mapTM = mapVar mapVar :: (a->b) -> VarMap a -> VarMap b mapVar f (VM { vm_bvar = bv, vm_fvar = fv }) = VM { vm_bvar = mapTM f bv, vm_fvar = mapVarEnv f fv } lkVar :: CmEnv -> Var -> VarMap a -> Maybe a lkVar env v | Just bv <- lookupCME env v = vm_bvar >.> lookupTM bv | otherwise = vm_fvar >.> lkFreeVar v xtVar :: CmEnv -> Var -> XT a -> VarMap a -> VarMap a xtVar env v f m | Just bv <- lookupCME env v = m { vm_bvar = vm_bvar m |> xtInt bv f } | otherwise = m { vm_fvar = vm_fvar m |> xtFreeVar v f } fdVar :: (a -> b -> b) -> VarMap a -> b -> b fdVar k m = foldTM k (vm_bvar m) . foldTM k (vm_fvar m) lkFreeVar :: Var -> VarEnv a -> Maybe a lkFreeVar var env = lookupVarEnv env var xtFreeVar :: Var -> XT a -> VarEnv a -> VarEnv a xtFreeVar v f m = alterVarEnv f m v
alexander-at-github/eta
compiler/ETA/Core/TrieMap.hs
bsd-3-clause
32,258
0
23
11,021
11,351
5,794
5,557
577
15
{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell, MultiParamTypeClasses, OverloadedStrings #-} module YesodCoreTest.StubSslOnly ( App ( App ) , Widget , resourcesApp ) where import Yesod.Core import qualified Web.ClientSession as CS data App = App mkYesod "App" [parseRoutes| / HomeR GET |] instance Yesod App where yesodMiddleware = defaultYesodMiddleware . (sslOnlyMiddleware 120) makeSessionBackend _ = sslOnlySessions $ fmap Just $ defaultClientSessionBackend 120 CS.defaultKeyFile getHomeR :: Handler Html getHomeR = defaultLayout [whamlet| <p> Welcome to my test application. |]
s9gf4ult/yesod
yesod-core/test/YesodCoreTest/StubSslOnly.hs
mit
674
0
8
157
123
71
52
19
1
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE helpset PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 2.0//EN" "http://java.sun.com/products/javahelp/helpset_2_0.dtd"> <helpset version="2.0" xml:lang="sq-AL"> <title>Windows WebDrivers</title> <maps> <homeID>top</homeID> <mapref location="map.jhm"/> </maps> <view> <name>TOC</name> <label>Contents</label> <type>org.zaproxy.zap.extension.help.ZapTocView</type> <data>toc.xml</data> </view> <view> <name>Index</name> <label>Index</label> <type>javax.help.IndexView</type> <data>index.xml</data> </view> <view> <name>Search</name> <label>Search</label> <type>javax.help.SearchView</type> <data engine="com.sun.java.help.search.DefaultSearchEngine"> JavaHelpSearch </data> </view> <view> <name>Favorites</name> <label>Favorites</label> <type>javax.help.FavoritesView</type> </view> </helpset>
thc202/zap-extensions
addOns/webdrivers/webdriverwindows/src/main/javahelp/org/zaproxy/zap/extension/webdriverwindows/resources/help_sq_AL/helpset_sq_AL.hs
apache-2.0
963
77
66
156
407
206
201
-1
-1
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE helpset PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 2.0//EN" "http://java.sun.com/products/javahelp/helpset_2_0.dtd"> <helpset version="2.0" xml:lang="ar-SA"> <title>OAST Support Add-on</title> <maps> <homeID>oast</homeID> <mapref location="map.jhm"/> </maps> <view> <name>TOC</name> <label>Contents</label> <type>org.zaproxy.zap.extension.help.ZapTocView</type> <data>toc.xml</data> </view> <view> <name>Index</name> <label>Index</label> <type>javax.help.IndexView</type> <data>index.xml</data> </view> <view> <name>Search</name> <label>Search</label> <type>javax.help.SearchView</type> <data engine="com.sun.java.help.search.DefaultSearchEngine"> JavaHelpSearch </data> </view> <view> <name>Favorites</name> <label>Favorites</label> <type>javax.help.FavoritesView</type> </view> </helpset>
thc202/zap-extensions
addOns/oast/src/main/javahelp/org/zaproxy/addon/oast/resources/help_ar_SA/helpset_ar_SA.hs
apache-2.0
965
77
67
157
413
209
204
-1
-1
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE helpset PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 2.0//EN" "http://java.sun.com/products/javahelp/helpset_2_0.dtd"> <helpset version="2.0" xml:lang="pt-BR"> <title>Directory List v2.3 LC</title> <maps> <homeID>directorylistv2_3_lc</homeID> <mapref location="map.jhm"/> </maps> <view> <name>TOC</name> <label>Contents</label> <type>org.zaproxy.zap.extension.help.ZapTocView</type> <data>toc.xml</data> </view> <view> <name>Index</name> <label>Index</label> <type>javax.help.IndexView</type> <data>index.xml</data> </view> <view> <name>Search</name> <label>Search</label> <type>javax.help.SearchView</type> <data engine="com.sun.java.help.search.DefaultSearchEngine"> JavaHelpSearch </data> </view> <view> <name>Favorites</name> <label>Favorites</label> <type>javax.help.FavoritesView</type> </view> </helpset>
kingthorin/zap-extensions
addOns/directorylistv2_3_lc/src/main/javahelp/help_pt_BR/helpset_pt_BR.hs
apache-2.0
984
78
66
158
414
210
204
-1
-1
{-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving, MagicHash, UnboxedTuples #-} -- !!! stress tests of copying/cloning primitive arrays -- Note: You can run this test manually with an argument (i.e. -- ./CopySmallArrayStressTest 10000) if you want to run the stress -- test for longer. {- Test strategy ============= We create an array of arrays of integers. Repeatedly we then either * allocate a new array in place of an old, or * copy a random segment of an array into another array (which might be the source array). By running this process long enough we hope to trigger any bugs related to garbage collection or edge cases. We only test copySmallMutableArray# and cloneSmallArray# as they are representative of all the primops. -} module Main ( main ) where import Debug.Trace (trace) import Control.Exception (assert) import Control.Monad import Control.Monad.Trans.State.Strict import Control.Monad.Trans.Class import GHC.Exts hiding (IsList(..)) import GHC.ST hiding (liftST) import Prelude hiding (length, read) import qualified Prelude as P import qualified Prelude as P import System.Environment import System.Random main :: IO () main = do args <- getArgs -- Number of copies to perform let numMods = case args of [] -> 100 [n] -> P.read n :: Int putStr (test_copyMutableArray numMods ++ "\n" ++ test_cloneMutableArray numMods ++ "\n" ) -- Number of arrays numArrays :: Int numArrays = 100 -- Maxmimum length of a sub-array maxLen :: Int maxLen = 1024 -- Create an array of arrays, with each sub-array having random length -- and content. setup :: Rng s (MArray s (MArray s Int)) setup = do len <- rnd (1, numArrays) marr <- liftST $ new_ len let go i | i >= len = return () | otherwise = do n <- rnd (1, maxLen) subarr <- liftST $ fromList [j*j | j <- [(0::Int)..n-1]] liftST $ write marr i subarr go (i+1) go 0 return marr -- Replace one of the sub-arrays with a newly allocated array. allocate :: MArray s (MArray s Int) -> Rng s () allocate marr = do ix <- rnd (0, length marr - 1) n <- rnd (1, maxLen) subarr <- liftST $ fromList [j*j | j <- [(0::Int)..n-1]] liftST $ write marr ix subarr type CopyFunction s a = MArray s a -> Int -> MArray s a -> Int -> Int -> ST s () -- Copy a random segment of an array onto another array, using the -- supplied copy function. copy :: MArray s (MArray s a) -> CopyFunction s a -> Rng s (Int, Int, Int, Int, Int) copy marr f = do six <- rnd (0, length marr - 1) dix <- rnd (0, length marr - 1) src <- liftST $ read marr six dst <- liftST $ read marr dix let srcLen = length src srcOff <- rnd (0, srcLen - 1) let dstLen = length dst dstOff <- rnd (0, dstLen - 1) n <- rnd (0, min (srcLen - srcOff) (dstLen - dstOff)) liftST $ f src srcOff dst dstOff n return (six, dix, srcOff, dstOff, n) type CloneFunction s a = MArray s a -> Int -> Int -> ST s (MArray s a) -- Clone a random segment of an array, replacing another array, using -- the supplied clone function. clone :: MArray s (MArray s a) -> CloneFunction s a -> Rng s (Int, Int, Int, Int) clone marr f = do six <- rnd (0, length marr - 1) dix <- rnd (0, length marr - 1) src <- liftST $ read marr six let srcLen = length src -- N.B. The array length might be zero if we previously cloned -- zero elements from some array. srcOff <- rnd (0, max 0 (srcLen - 1)) n <- rnd (0, srcLen - srcOff) dst <- liftST $ f src srcOff n liftST $ write marr dix dst return (six, dix, srcOff, n) ------------------------------------------------------------------------ -- copySmallMutableArray# -- Copy a slice of the source array into a destination array and check -- that the copy succeeded. test_copyMutableArray :: Int -> String test_copyMutableArray numMods = runST $ run $ do marr <- local setup marrRef <- setup let go i | i >= numMods = return "test_copyMutableArray: OK" | otherwise = do -- Either allocate or copy alloc <- rnd (True, False) if alloc then doAlloc else doCopy go (i+1) doAlloc = do local $ allocate marr allocate marrRef doCopy = do inp <- liftST $ asList marr _ <- local $ copy marr copyMArray (six, dix, srcOff, dstOff, n) <- copy marrRef copyMArraySlow el <- liftST $ asList marr elRef <- liftST $ asList marrRef when (el /= elRef) $ fail inp el elRef six dix srcOff dstOff n go 0 where fail inp el elRef six dix srcOff dstOff n = error $ "test_copyMutableArray: FAIL\n" ++ " Input: " ++ unlinesShow inp ++ " Copy: six: " ++ show six ++ " dix: " ++ show dix ++ " srcOff: " ++ show srcOff ++ " dstOff: " ++ show dstOff ++ " n: " ++ show n ++ "\n" ++ "Expected: " ++ unlinesShow elRef ++ " Actual: " ++ unlinesShow el asList :: MArray s (MArray s a) -> ST s [[a]] asList marr = toListM =<< mapArrayM toListM marr unlinesShow :: Show a => [a] -> String unlinesShow = concatMap (\ x -> show x ++ "\n") ------------------------------------------------------------------------ -- cloneSmallMutableArray# -- Copy a slice of the source array into a destination array and check -- that the copy succeeded. test_cloneMutableArray :: Int -> String test_cloneMutableArray numMods = runST $ run $ do marr <- local setup marrRef <- setup let go i | i >= numMods = return "test_cloneMutableArray: OK" | otherwise = do -- Either allocate or clone alloc <- rnd (True, False) if alloc then doAlloc else doClone go (i+1) doAlloc = do local $ allocate marr allocate marrRef doClone = do inp <- liftST $ asList marr _ <- local $ clone marr cloneMArray (six, dix, srcOff, n) <- clone marrRef cloneMArraySlow el <- liftST $ asList marr elRef <- liftST $ asList marrRef when (el /= elRef) $ fail inp el elRef six dix srcOff n go 0 where fail inp el elRef six dix srcOff n = error $ "test_cloneMutableArray: FAIL\n" ++ " Input: " ++ unlinesShow inp ++ " Clone: six: " ++ show six ++ " dix: " ++ show dix ++ " srcOff: " ++ show srcOff ++ " n: " ++ show n ++ "\n" ++ "Expected: " ++ unlinesShow elRef ++ " Actual: " ++ unlinesShow el ------------------------------------------------------------------------ -- Convenience wrappers for SmallArray# and SmallMutableArray# data Array a = Array { unArray :: SmallArray# a , lengthA :: {-# UNPACK #-} !Int} data MArray s a = MArray { unMArray :: SmallMutableArray# s a , lengthM :: {-# UNPACK #-} !Int} class IArray a where length :: a -> Int instance IArray (Array a) where length = lengthA instance IArray (MArray s a) where length = lengthM instance Eq a => Eq (Array a) where arr1 == arr2 = toList arr1 == toList arr2 new :: Int -> a -> ST s (MArray s a) new n@(I# n#) a = assert (n >= 0) $ ST $ \s# -> case newSmallArray# n# a s# of (# s2#, marr# #) -> (# s2#, MArray marr# n #) new_ :: Int -> ST s (MArray s a) new_ n = new n (error "Undefined element") write :: MArray s a -> Int -> a -> ST s () write marr i@(I# i#) a = assert (i >= 0) $ assert (i < length marr) $ ST $ \ s# -> case writeSmallArray# (unMArray marr) i# a s# of s2# -> (# s2#, () #) read :: MArray s a -> Int -> ST s a read marr i@(I# i#) = assert (i >= 0) $ assert (i < length marr) $ ST $ \ s# -> readSmallArray# (unMArray marr) i# s# index :: Array a -> Int -> a index arr i@(I# i#) = assert (i >= 0) $ assert (i < length arr) $ case indexSmallArray# (unArray arr) i# of (# a #) -> a unsafeFreeze :: MArray s a -> ST s (Array a) unsafeFreeze marr = ST $ \ s# -> case unsafeFreezeSmallArray# (unMArray marr) s# of (# s2#, arr# #) -> (# s2#, Array arr# (length marr) #) toList :: Array a -> [a] toList arr = go 0 where go i | i >= length arr = [] | otherwise = index arr i : go (i+1) fromList :: [e] -> ST s (MArray s e) fromList es = do marr <- new_ n let go !_ [] = return () go i (x:xs) = write marr i x >> go (i+1) xs go 0 es return marr where n = P.length es mapArrayM :: (a -> ST s b) -> MArray s a -> ST s (MArray s b) mapArrayM f src = do dst <- new_ n let go i | i >= n = return dst | otherwise = do el <- read src i el' <- f el write dst i el' go (i+1) go 0 where n = length src toListM :: MArray s e -> ST s [e] toListM marr = sequence [read marr i | i <- [0..(length marr)-1]] ------------------------------------------------------------------------ -- Wrappers around copy/clone primops copyMArray :: MArray s a -> Int -> MArray s a -> Int -> Int -> ST s () copyMArray src six@(I# six#) dst dix@(I# dix#) n@(I# n#) = assert (six >= 0) $ assert (six + n <= length src) $ assert (dix >= 0) $ assert (dix + n <= length dst) $ ST $ \ s# -> case copySmallMutableArray# (unMArray src) six# (unMArray dst) dix# n# s# of s2# -> (# s2#, () #) cloneMArray :: MArray s a -> Int -> Int -> ST s (MArray s a) cloneMArray marr off@(I# off#) n@(I# n#) = assert (off >= 0) $ assert (off + n <= length marr) $ ST $ \ s# -> case cloneSmallMutableArray# (unMArray marr) off# n# s# of (# s2#, marr2 #) -> (# s2#, MArray marr2 n #) ------------------------------------------------------------------------ -- Manual versions of copy/clone primops. Used to validate the -- primops copyMArraySlow :: MArray s e -> Int -> MArray s e -> Int -> Int -> ST s () copyMArraySlow !src !six !dst !dix n = assert (six >= 0) $ assert (six + n <= length src) $ assert (dix >= 0) $ assert (dix + n <= length dst) $ if six < dix then goB (six+n-1) (dix+n-1) 0 -- Copy backwards else goF six dix 0 -- Copy forwards where goF !i !j c | c >= n = return () | otherwise = do b <- read src i write dst j b goF (i+1) (j+1) (c+1) goB !i !j c | c >= n = return () | otherwise = do b <- read src i write dst j b goB (i-1) (j-1) (c+1) cloneMArraySlow :: MArray s a -> Int -> Int -> ST s (MArray s a) cloneMArraySlow !marr !off n = assert (off >= 0) $ assert (off + n <= length marr) $ do marr2 <- new_ n let go !i !j c | c >= n = return marr2 | otherwise = do b <- read marr i write marr2 j b go (i+1) (j+1) (c+1) go off 0 0 ------------------------------------------------------------------------ -- Utilities for simplifying RNG passing newtype Rng s a = Rng { unRng :: StateT StdGen (ST s) a } deriving Monad -- Same as 'randomR', but using the RNG state kept in the 'Rng' monad. rnd :: Random a => (a, a) -> Rng s a rnd r = Rng $ do g <- get let (x, g') = randomR r g put g' return x -- Run a sub-computation without affecting the RNG state. local :: Rng s a -> Rng s a local m = Rng $ do g <- get x <- unRng m put g return x liftST :: ST s a -> Rng s a liftST m = Rng $ lift m run :: Rng s a -> ST s a run = flip evalStateT (mkStdGen 13) . unRng
frantisekfarka/ghc-dsi
testsuite/tests/codeGen/should_run/CopySmallArrayStressTest.hs
bsd-3-clause
11,860
0
24
3,676
4,304
2,117
2,187
273
2
{-# OPTIONS_GHC -fwarn-safe #-} {-# OPTIONS_GHC -fwarn-unsafe #-} {-# LANGUAGE TemplateHaskell #-} -- | Unsafe as uses TH module UnsafeWarn02 where f :: Int f = 1
urbanslug/ghc
testsuite/tests/safeHaskell/safeInfered/UnsafeWarn02.hs
bsd-3-clause
166
0
4
30
18
13
5
6
1